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

(cherry picked from commit cae9fbf3213987e7d263845431dfac10a2ecb3b0)

# Conflicts:
#	data/src/main/sqldelight/tachiyomi/migrations/10.sqm
This commit is contained in:
Luca Auer
2026-02-14 19:43:31 +01:00
committed by Jobobby04
parent bcaf7f6415
commit 905a1c1230
7 changed files with 19 additions and 0 deletions
@@ -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
@@ -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)
@@ -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
@@ -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;
@@ -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
@@ -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
@@ -27,3 +27,13 @@ AND chapters.scanlator = excluded_scanlators.scanlator
WHERE favorite = 1
AND date_fetch > date_added
ORDER BY date_fetch DESC;
-- 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);