Optimize library query
This commit is contained in:
parent
8b67255186
commit
36aabf23e1
@ -17,7 +17,7 @@ class DbOpenHelper(context: Context)
|
|||||||
/**
|
/**
|
||||||
* Version of the database.
|
* Version of the database.
|
||||||
*/
|
*/
|
||||||
const val DATABASE_VERSION = 7
|
const val DATABASE_VERSION = 8
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate(db: SQLiteDatabase) = with(db) {
|
override fun onCreate(db: SQLiteDatabase) = with(db) {
|
||||||
@ -30,8 +30,9 @@ class DbOpenHelper(context: Context)
|
|||||||
|
|
||||||
// DB indexes
|
// DB indexes
|
||||||
execSQL(MangaTable.createUrlIndexQuery)
|
execSQL(MangaTable.createUrlIndexQuery)
|
||||||
execSQL(MangaTable.createFavoriteIndexQuery)
|
execSQL(MangaTable.createLibraryIndexQuery)
|
||||||
execSQL(ChapterTable.createMangaIdIndexQuery)
|
execSQL(ChapterTable.createMangaIdIndexQuery)
|
||||||
|
execSQL(ChapterTable.createUnreadChaptersIndexQuery)
|
||||||
execSQL(HistoryTable.createChapterIdIndexQuery)
|
execSQL(HistoryTable.createChapterIdIndexQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +61,11 @@ class DbOpenHelper(context: Context)
|
|||||||
if (oldVersion < 7) {
|
if (oldVersion < 7) {
|
||||||
db.execSQL(TrackTable.addLibraryId)
|
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) {
|
override fun onConfigure(db: SQLiteDatabase) {
|
||||||
|
@ -49,6 +49,10 @@ object ChapterTable {
|
|||||||
val createMangaIdIndexQuery: String
|
val createMangaIdIndexQuery: String
|
||||||
get() = "CREATE INDEX ${TABLE}_${COL_MANGA_ID}_index ON $TABLE($COL_MANGA_ID)"
|
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
|
val sourceOrderUpdateQuery: String
|
||||||
get() = "ALTER TABLE $TABLE ADD COLUMN $COL_SOURCE_ORDER INTEGER DEFAULT 0"
|
get() = "ALTER TABLE $TABLE ADD COLUMN $COL_SOURCE_ORDER INTEGER DEFAULT 0"
|
||||||
|
|
||||||
|
@ -60,6 +60,7 @@ object MangaTable {
|
|||||||
val createUrlIndexQuery: String
|
val createUrlIndexQuery: String
|
||||||
get() = "CREATE INDEX ${TABLE}_${COL_URL}_index ON $TABLE($COL_URL)"
|
get() = "CREATE INDEX ${TABLE}_${COL_URL}_index ON $TABLE($COL_URL)"
|
||||||
|
|
||||||
val createFavoriteIndexQuery: String
|
val createLibraryIndexQuery: String
|
||||||
get() = "CREATE INDEX ${TABLE}_${COL_FAVORITE}_index ON $TABLE($COL_FAVORITE)"
|
get() = "CREATE INDEX library_${COL_FAVORITE}_index ON $TABLE($COL_FAVORITE) " +
|
||||||
|
"WHERE $COL_FAVORITE = 1"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user