From 36aabf23e116e29c71d24e496d47ae2b24b8661d Mon Sep 17 00:00:00 2001 From: inorichi Date: Fri, 9 Nov 2018 11:59:17 +0100 Subject: [PATCH] Optimize library query --- .../eu/kanade/tachiyomi/data/database/DbOpenHelper.kt | 10 ++++++++-- .../tachiyomi/data/database/tables/ChapterTable.kt | 4 ++++ .../tachiyomi/data/database/tables/MangaTable.kt | 5 +++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenHelper.kt index 998a5a1a7b..5bdbfa7796 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenHelper.kt @@ -17,7 +17,7 @@ class DbOpenHelper(context: Context) /** * Version of the database. */ - const val DATABASE_VERSION = 7 + const val DATABASE_VERSION = 8 } override fun onCreate(db: SQLiteDatabase) = with(db) { @@ -30,8 +30,9 @@ class DbOpenHelper(context: Context) // DB indexes execSQL(MangaTable.createUrlIndexQuery) - execSQL(MangaTable.createFavoriteIndexQuery) + execSQL(MangaTable.createLibraryIndexQuery) execSQL(ChapterTable.createMangaIdIndexQuery) + execSQL(ChapterTable.createUnreadChaptersIndexQuery) execSQL(HistoryTable.createChapterIdIndexQuery) } @@ -60,6 +61,11 @@ class DbOpenHelper(context: Context) if (oldVersion < 7) { db.execSQL(TrackTable.addLibraryId) } + if (oldVersion < 8) { + db.execSQL("DROP INDEX IF EXISTS mangas_favorite_index") + db.execSQL(MangaTable.createLibraryIndexQuery) + db.execSQL(ChapterTable.createUnreadChaptersIndexQuery) + } } override fun onConfigure(db: SQLiteDatabase) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/ChapterTable.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/ChapterTable.kt index a031c94d45..a2350caa0b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/ChapterTable.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/ChapterTable.kt @@ -49,6 +49,10 @@ object ChapterTable { val createMangaIdIndexQuery: String get() = "CREATE INDEX ${TABLE}_${COL_MANGA_ID}_index ON $TABLE($COL_MANGA_ID)" + val createUnreadChaptersIndexQuery: String + get() = "CREATE INDEX ${TABLE}_unread_by_manga_index ON $TABLE($COL_MANGA_ID, $COL_READ) " + + "WHERE $COL_READ = 0" + val sourceOrderUpdateQuery: String get() = "ALTER TABLE $TABLE ADD COLUMN $COL_SOURCE_ORDER INTEGER DEFAULT 0" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt index 199e86f71d..2b1ff7458d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt @@ -60,6 +60,7 @@ object MangaTable { val createUrlIndexQuery: String get() = "CREATE INDEX ${TABLE}_${COL_URL}_index ON $TABLE($COL_URL)" - val createFavoriteIndexQuery: String - get() = "CREATE INDEX ${TABLE}_${COL_FAVORITE}_index ON $TABLE($COL_FAVORITE)" + val createLibraryIndexQuery: String + get() = "CREATE INDEX library_${COL_FAVORITE}_index ON $TABLE($COL_FAVORITE) " + + "WHERE $COL_FAVORITE = 1" }