From dd983c803b6fe1a29946447ca818eaefdd7928ff Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 17 Jun 2022 22:35:21 -0400 Subject: [PATCH] Delete unused database queries/resolvers --- .../java/eu/kanade/tachiyomi/AppModule.kt | 2 +- .../tachiyomi/data/database/DbOpenCallback.kt | 5 +- .../tachiyomi/data/database/DbProvider.kt | 1 - .../data/database/queries/ChapterQueries.kt | 23 -------- .../data/database/queries/RawQueries.kt | 18 ------- .../resolvers/ChapterBackupPutResolver.kt | 34 ------------ .../ChapterKnownBackupPutResolver.kt | 34 ------------ .../resolvers/HistoryUpsertResolver.kt | 52 ------------------- 8 files changed, 2 insertions(+), 167 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterBackupPutResolver.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterKnownBackupPutResolver.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/HistoryUpsertResolver.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt index 2a65241e96..0b27157561 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt @@ -42,7 +42,7 @@ class AppModule(val app: Application) : InjektModule { addSingletonFactory { val configuration = SupportSQLiteOpenHelper.Configuration.builder(app) .callback(DbOpenCallback()) - .name(DbOpenCallback.DATABASE_NAME) + .name(DbOpenCallback.DATABASE_FILENAME) .noBackupDirectory(false) .build() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenCallback.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenCallback.kt index d5cf594030..14905d8760 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenCallback.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenCallback.kt @@ -9,10 +9,7 @@ import logcat.logcat class DbOpenCallback : SupportSQLiteOpenHelper.Callback(Database.Schema.version) { companion object { - /** - * Name of the database file. - */ - const val DATABASE_NAME = "tachiyomi.db" + const val DATABASE_FILENAME = "tachiyomi.db" } override fun onCreate(db: SupportSQLiteDatabase) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/DbProvider.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/DbProvider.kt index 4609852b96..ff42ff75b6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/DbProvider.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/DbProvider.kt @@ -3,6 +3,5 @@ package eu.kanade.tachiyomi.data.database import com.pushtorefresh.storio.sqlite.impl.DefaultStorIOSQLite interface DbProvider { - val db: DefaultStorIOSQLite } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/ChapterQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/ChapterQueries.kt index 9e237d3563..a2a8a96cc7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/ChapterQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/ChapterQueries.kt @@ -6,8 +6,6 @@ import eu.kanade.tachiyomi.data.database.DbProvider import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaChapter -import eu.kanade.tachiyomi.data.database.resolvers.ChapterBackupPutResolver -import eu.kanade.tachiyomi.data.database.resolvers.ChapterKnownBackupPutResolver import eu.kanade.tachiyomi.data.database.resolvers.ChapterProgressPutResolver import eu.kanade.tachiyomi.data.database.resolvers.MangaChapterGetResolver import eu.kanade.tachiyomi.data.database.tables.ChapterTable @@ -49,17 +47,6 @@ interface ChapterQueries : DbProvider { ) .prepare() - fun getChapter(url: String) = db.get() - .`object`(Chapter::class.java) - .withQuery( - Query.builder() - .table(ChapterTable.TABLE) - .where("${ChapterTable.COL_URL} = ?") - .whereArgs(url) - .build(), - ) - .prepare() - fun getChapter(url: String, mangaId: Long) = db.get() .`object`(Chapter::class.java) .withQuery( @@ -75,16 +62,6 @@ interface ChapterQueries : DbProvider { fun deleteChapters(chapters: List) = db.delete().objects(chapters).prepare() - fun updateChaptersBackup(chapters: List) = db.put() - .objects(chapters) - .withPutResolver(ChapterBackupPutResolver()) - .prepare() - - fun updateKnownChaptersBackup(chapters: List) = db.put() - .objects(chapters) - .withPutResolver(ChapterKnownBackupPutResolver()) - .prepare() - fun updateChapterProgress(chapter: Chapter) = db.put() .`object`(chapter) .withPutResolver(ChapterProgressPutResolver()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt index 6ae95e670c..9e361fe999 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt @@ -51,24 +51,6 @@ fun getRecentsQuery() = ORDER BY ${Chapter.COL_DATE_UPLOAD} DESC """ -fun getHistoryByMangaId() = - """ - SELECT ${History.TABLE}.* - FROM ${History.TABLE} - JOIN ${Chapter.TABLE} - ON ${History.TABLE}.${History.COL_CHAPTER_ID} = ${Chapter.TABLE}.${Chapter.COL_ID} - WHERE ${Chapter.TABLE}.${Chapter.COL_MANGA_ID} = ? AND ${History.TABLE}.${History.COL_CHAPTER_ID} = ${Chapter.TABLE}.${Chapter.COL_ID} -""" - -fun getHistoryByChapterUrl() = - """ - SELECT ${History.TABLE}.* - FROM ${History.TABLE} - JOIN ${Chapter.TABLE} - ON ${History.TABLE}.${History.COL_CHAPTER_ID} = ${Chapter.TABLE}.${Chapter.COL_ID} - WHERE ${Chapter.TABLE}.${Chapter.COL_URL} = ? AND ${History.TABLE}.${History.COL_CHAPTER_ID} = ${Chapter.TABLE}.${Chapter.COL_ID} -""" - fun getLastReadMangaQuery() = """ SELECT ${Manga.TABLE}.*, MAX(${History.TABLE}.${History.COL_LAST_READ}) AS max diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterBackupPutResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterBackupPutResolver.kt deleted file mode 100644 index 7fb01a821e..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterBackupPutResolver.kt +++ /dev/null @@ -1,34 +0,0 @@ -package eu.kanade.tachiyomi.data.database.resolvers - -import androidx.core.content.contentValuesOf -import com.pushtorefresh.storio.sqlite.StorIOSQLite -import com.pushtorefresh.storio.sqlite.operations.put.PutResolver -import com.pushtorefresh.storio.sqlite.operations.put.PutResult -import com.pushtorefresh.storio.sqlite.queries.UpdateQuery -import eu.kanade.tachiyomi.data.database.inTransactionReturn -import eu.kanade.tachiyomi.data.database.models.Chapter -import eu.kanade.tachiyomi.data.database.tables.ChapterTable - -class ChapterBackupPutResolver : PutResolver() { - - override fun performPut(db: StorIOSQLite, chapter: Chapter) = db.inTransactionReturn { - val updateQuery = mapToUpdateQuery(chapter) - val contentValues = mapToContentValues(chapter) - - val numberOfRowsUpdated = db.lowLevel().update(updateQuery, contentValues) - PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) - } - - fun mapToUpdateQuery(chapter: Chapter) = UpdateQuery.builder() - .table(ChapterTable.TABLE) - .where("${ChapterTable.COL_URL} = ?") - .whereArgs(chapter.url) - .build() - - fun mapToContentValues(chapter: Chapter) = - contentValuesOf( - ChapterTable.COL_READ to chapter.read, - ChapterTable.COL_BOOKMARK to chapter.bookmark, - ChapterTable.COL_LAST_PAGE_READ to chapter.last_page_read, - ) -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterKnownBackupPutResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterKnownBackupPutResolver.kt deleted file mode 100644 index da62066c4a..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterKnownBackupPutResolver.kt +++ /dev/null @@ -1,34 +0,0 @@ -package eu.kanade.tachiyomi.data.database.resolvers - -import androidx.core.content.contentValuesOf -import com.pushtorefresh.storio.sqlite.StorIOSQLite -import com.pushtorefresh.storio.sqlite.operations.put.PutResolver -import com.pushtorefresh.storio.sqlite.operations.put.PutResult -import com.pushtorefresh.storio.sqlite.queries.UpdateQuery -import eu.kanade.tachiyomi.data.database.inTransactionReturn -import eu.kanade.tachiyomi.data.database.models.Chapter -import eu.kanade.tachiyomi.data.database.tables.ChapterTable - -class ChapterKnownBackupPutResolver : PutResolver() { - - override fun performPut(db: StorIOSQLite, chapter: Chapter) = db.inTransactionReturn { - val updateQuery = mapToUpdateQuery(chapter) - val contentValues = mapToContentValues(chapter) - - val numberOfRowsUpdated = db.lowLevel().update(updateQuery, contentValues) - PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) - } - - fun mapToUpdateQuery(chapter: Chapter) = UpdateQuery.builder() - .table(ChapterTable.TABLE) - .where("${ChapterTable.COL_ID} = ?") - .whereArgs(chapter.id) - .build() - - fun mapToContentValues(chapter: Chapter) = - contentValuesOf( - ChapterTable.COL_READ to chapter.read, - ChapterTable.COL_BOOKMARK to chapter.bookmark, - ChapterTable.COL_LAST_PAGE_READ to chapter.last_page_read, - ) -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/HistoryUpsertResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/HistoryUpsertResolver.kt deleted file mode 100644 index 908aca16d3..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/HistoryUpsertResolver.kt +++ /dev/null @@ -1,52 +0,0 @@ -package eu.kanade.tachiyomi.data.database.resolvers - -import androidx.annotation.NonNull -import androidx.core.content.contentValuesOf -import com.pushtorefresh.storio.sqlite.StorIOSQLite -import com.pushtorefresh.storio.sqlite.operations.put.PutResult -import com.pushtorefresh.storio.sqlite.queries.Query -import com.pushtorefresh.storio.sqlite.queries.UpdateQuery -import eu.kanade.tachiyomi.data.database.inTransactionReturn -import eu.kanade.tachiyomi.data.database.mappers.HistoryPutResolver -import eu.kanade.tachiyomi.data.database.models.History -import eu.kanade.tachiyomi.data.database.tables.HistoryTable - -class HistoryUpsertResolver : HistoryPutResolver() { - - /** - * Updates last_read time of chapter - */ - override fun performPut(@NonNull db: StorIOSQLite, @NonNull history: History): PutResult = db.inTransactionReturn { - val updateQuery = mapToUpdateQuery(history) - - val cursor = db.lowLevel().query( - Query.builder() - .table(updateQuery.table()) - .where(updateQuery.where()) - .whereArgs(updateQuery.whereArgs()) - .build(), - ) - - cursor.use { putCursor -> - if (putCursor.count == 0) { - val insertQuery = mapToInsertQuery(history) - val insertedId = db.lowLevel().insert(insertQuery, mapToContentValues(history)) - PutResult.newInsertResult(insertedId, insertQuery.table()) - } else { - val numberOfRowsUpdated = db.lowLevel().update(updateQuery, mapToUpdateContentValues(history)) - PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) - } - } - } - - override fun mapToUpdateQuery(obj: History) = UpdateQuery.builder() - .table(HistoryTable.TABLE) - .where("${HistoryTable.COL_CHAPTER_ID} = ?") - .whereArgs(obj.chapter_id) - .build() - - private fun mapToUpdateContentValues(history: History) = - contentValuesOf( - HistoryTable.COL_LAST_READ to history.last_read, - ) -}