Optimize database indexes and clean up schema (#1603)

* Update `excluded_scanlators` index to a composite index on `manga_id` and `scanlator`.
* Convert `idx_history_last_read` into a partial index for entries where `last_read > 0`.
* Remove redundant `idx_manga_sync_manga_id` index.
* Remove unused `last_modified_at` column and its associated trigger from `mangas_categories`.
* Sync migration files with schema changes.
This commit is contained in:
Cuong-Tran 2026-04-23 00:02:00 +07:00
parent 8bb8d7ccb7
commit bf9b663581
4 changed files with 5 additions and 8 deletions

View file

@ -5,8 +5,7 @@ CREATE TABLE excluded_scanlators(
ON DELETE CASCADE
);
CREATE INDEX excluded_scanlators_manga_id_index ON excluded_scanlators(manga_id);
CREATE INDEX idx_excluded_scanlators_scanlator ON excluded_scanlators(scanlator);
CREATE INDEX idx_excluded_scanlators_manga_id_scanlator ON excluded_scanlators(manga_id, scanlator);
insert:
INSERT INTO excluded_scanlators(manga_id, scanlator)

View file

@ -10,7 +10,7 @@ CREATE TABLE history(
);
CREATE INDEX history_history_chapter_id_index ON history(chapter_id);
CREATE INDEX idx_history_last_read ON history(last_read);
CREATE INDEX idx_history_last_read ON history(last_read) WHERE last_read > 0;
getHistoryByMangaId:
SELECT

View file

@ -20,8 +20,6 @@ CREATE TABLE manga_sync(
ON DELETE CASCADE
);
CREATE INDEX idx_manga_sync_manga_id ON manga_sync(manga_id);
delete:
DELETE FROM manga_sync
WHERE manga_id = :mangaId AND sync_id = :syncId;

View file

@ -4,6 +4,6 @@ CREATE INDEX IF NOT EXISTS idx_mangas_source ON mangas(source);
CREATE INDEX IF NOT EXISTS idx_chapters_url ON chapters(url);
CREATE INDEX IF NOT EXISTS idx_mangas_categories_manga_id ON mangas_categories(manga_id);
CREATE INDEX IF NOT EXISTS idx_mangas_categories_category_id ON mangas_categories(category_id);
CREATE INDEX IF NOT EXISTS idx_excluded_scanlators_scanlator ON excluded_scanlators(scanlator);
CREATE INDEX IF NOT EXISTS idx_manga_sync_manga_id ON manga_sync(manga_id);
CREATE INDEX IF NOT EXISTS idx_history_last_read ON history(last_read);
DROP INDEX IF EXISTS excluded_scanlators_manga_id_index;
CREATE INDEX IF NOT EXISTS idx_excluded_scanlators_manga_id_scanlator ON excluded_scanlators(manga_id, scanlator);
CREATE INDEX IF NOT EXISTS idx_history_last_read ON history(last_read) WHERE last_read > 0;