Add missing indexes to improve database query performance (mihonapp/mihon#2950)

(cherry picked from commit cae9fbf3213987e7d263845431dfac10a2ecb3b0)
This commit is contained in:
Luca Auer 2026-02-14 19:43:31 +01:00 committed by Cuong-Tran
parent 80ea323281
commit 8bb8d7ccb7
7 changed files with 18 additions and 0 deletions

View file

@ -22,6 +22,7 @@ CREATE TABLE chapters(
CREATE INDEX chapters_manga_id_index ON chapters(manga_id);
CREATE INDEX chapters_unread_by_manga_index ON chapters(manga_id, read) WHERE read = 0;
CREATE INDEX idx_chapters_url ON chapters(url);
CREATE TRIGGER update_last_modified_at_chapters
AFTER UPDATE ON chapters

View file

@ -6,6 +6,7 @@ CREATE TABLE excluded_scanlators(
);
CREATE INDEX excluded_scanlators_manga_id_index ON excluded_scanlators(manga_id);
CREATE INDEX idx_excluded_scanlators_scanlator ON excluded_scanlators(scanlator);
insert:
INSERT INTO excluded_scanlators(manga_id, scanlator)

View file

@ -10,6 +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);
getHistoryByMangaId:
SELECT

View file

@ -20,6 +20,8 @@ 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

@ -34,6 +34,7 @@ CREATE TABLE mangas(
CREATE INDEX library_favorite_index ON mangas(favorite) WHERE favorite = 1;
CREATE INDEX mangas_url_index ON mangas(url);
CREATE INDEX idx_mangas_source ON mangas(source);
CREATE TRIGGER update_last_favorited_at_mangas
AFTER UPDATE OF favorite ON mangas

View file

@ -8,6 +8,9 @@ CREATE TABLE mangas_categories(
ON DELETE CASCADE
);
CREATE INDEX idx_mangas_categories_manga_id ON mangas_categories(manga_id);
CREATE INDEX idx_mangas_categories_category_id ON mangas_categories(category_id);
CREATE TRIGGER insert_manga_category_update_version AFTER INSERT ON mangas_categories
BEGIN
UPDATE mangas

View file

@ -0,0 +1,9 @@
-- Migration to add performance indexes
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);