From 2caf220b184d9ee5916ad205b5609da116a9409f Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 24 Apr 2022 16:20:46 -0400 Subject: [PATCH] Remove some unused StorIO queries/resolvers --- .../data/database/queries/CategoryQueries.kt | 2 - .../data/database/queries/HistoryQueries.kt | 8 --- .../database/queries/MangaCategoryQueries.kt | 2 - .../data/database/queries/MangaQueries.kt | 21 -------- .../data/database/queries/RawQueries.kt | 38 -------------- .../MangaChapterHistoryGetResolver.kt | 51 ------------------- .../resolvers/MangaTitlePutResolver.kt | 32 ------------ 7 files changed, 154 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaChapterHistoryGetResolver.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaTitlePutResolver.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/CategoryQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/CategoryQueries.kt index f940a50c72..167a8241e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/CategoryQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/CategoryQueries.kt @@ -33,7 +33,5 @@ interface CategoryQueries : DbProvider { fun insertCategories(categories: List) = db.put().objects(categories).prepare() - fun deleteCategory(category: Category) = db.delete().`object`(category).prepare() - fun deleteCategories(categories: List) = db.delete().objects(categories).prepare() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt index fd93497899..96c23b82a7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt @@ -51,14 +51,6 @@ interface HistoryQueries : DbProvider { .withPutResolver(HistoryUpsertResolver()) .prepare() - fun dropHistoryTable() = db.delete() - .byQuery( - DeleteQuery.builder() - .table(HistoryTable.TABLE) - .build(), - ) - .prepare() - fun deleteHistoryNoLastRead() = db.delete() .byQuery( DeleteQuery.builder() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaCategoryQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaCategoryQueries.kt index 571cd23aa4..9f36dc578d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaCategoryQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaCategoryQueries.kt @@ -10,8 +10,6 @@ import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable interface MangaCategoryQueries : DbProvider { - fun insertMangaCategory(mangaCategory: MangaCategory) = db.put().`object`(mangaCategory).prepare() - fun insertMangasCategories(mangasCategories: List) = db.put().objects(mangasCategories).prepare() fun deleteOldMangasCategories(mangas: List) = db.delete() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt index 54bf429683..04518cf546 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt @@ -14,7 +14,6 @@ import eu.kanade.tachiyomi.data.database.resolvers.MangaCoverLastModifiedPutReso import eu.kanade.tachiyomi.data.database.resolvers.MangaFavoritePutResolver import eu.kanade.tachiyomi.data.database.resolvers.MangaFlagsPutResolver import eu.kanade.tachiyomi.data.database.resolvers.MangaLastUpdatedPutResolver -import eu.kanade.tachiyomi.data.database.resolvers.MangaTitlePutResolver import eu.kanade.tachiyomi.data.database.resolvers.SourceIdMangaCountGetResolver import eu.kanade.tachiyomi.data.database.tables.CategoryTable import eu.kanade.tachiyomi.data.database.tables.ChapterTable @@ -117,11 +116,6 @@ interface MangaQueries : DbProvider { .withPutResolver(MangaFlagsPutResolver(MangaTable.COL_VIEWER, Manga::viewer_flags)) .prepare() - fun updateViewerFlags(manga: List) = db.put() - .objects(manga) - .withPutResolver(MangaFlagsPutResolver(MangaTable.COL_VIEWER, Manga::viewer_flags)) - .prepare() - fun updateLastUpdated(manga: Manga) = db.put() .`object`(manga) .withPutResolver(MangaLastUpdatedPutResolver()) @@ -132,11 +126,6 @@ interface MangaQueries : DbProvider { .withPutResolver(MangaFavoritePutResolver()) .prepare() - fun updateMangaTitle(manga: Manga) = db.put() - .`object`(manga) - .withPutResolver(MangaTitlePutResolver()) - .prepare() - fun updateMangaCoverLastModified(manga: Manga) = db.put() .`object`(manga) .withPutResolver(MangaCoverLastModifiedPutResolver()) @@ -174,16 +163,6 @@ interface MangaQueries : DbProvider { ) .prepare() - fun getTotalChapterManga() = db.get() - .listOfObjects(Manga::class.java) - .withQuery( - RawQuery.builder() - .query(getTotalChapterMangaQuery()) - .observesTables(MangaTable.TABLE) - .build(), - ) - .prepare() - fun getLatestChapterManga() = db.get() .listOfObjects(Manga::class.java) .withQuery( 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 3488119392..c1209d4c1e 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 @@ -52,34 +52,6 @@ fun getRecentsQuery() = ORDER BY ${Chapter.COL_DATE_UPLOAD} DESC """ -/** - * Query to get the recently read chapters of manga from the library up to a date. - * The max_last_read table contains the most recent chapters grouped by manga - * The select statement returns all information of chapters that have the same id as the chapter in max_last_read - * and are read after the given time period - */ -fun getRecentMangasQuery(search: String = "") = - """ - SELECT ${Manga.TABLE}.${Manga.COL_URL} as mangaUrl, ${Manga.TABLE}.*, ${Chapter.TABLE}.*, ${History.TABLE}.* - FROM ${Manga.TABLE} - JOIN ${Chapter.TABLE} - ON ${Manga.TABLE}.${Manga.COL_ID} = ${Chapter.TABLE}.${Chapter.COL_MANGA_ID} - JOIN ${History.TABLE} - ON ${Chapter.TABLE}.${Chapter.COL_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID} - JOIN ( - SELECT ${Chapter.TABLE}.${Chapter.COL_MANGA_ID},${Chapter.TABLE}.${Chapter.COL_ID} as ${History.COL_CHAPTER_ID}, MAX(${History.TABLE}.${History.COL_LAST_READ}) as ${History.COL_LAST_READ} - FROM ${Chapter.TABLE} JOIN ${History.TABLE} - ON ${Chapter.TABLE}.${Chapter.COL_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID} - GROUP BY ${Chapter.TABLE}.${Chapter.COL_MANGA_ID} - ) AS max_last_read - ON ${Chapter.TABLE}.${Chapter.COL_MANGA_ID} = max_last_read.${Chapter.COL_MANGA_ID} - WHERE ${History.TABLE}.${History.COL_LAST_READ} > ? - AND max_last_read.${History.COL_CHAPTER_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID} - AND lower(${Manga.TABLE}.${Manga.COL_TITLE}) LIKE '%$search%' - ORDER BY max_last_read.${History.COL_LAST_READ} DESC - LIMIT ? OFFSET ? -""" - fun getHistoryByMangaId() = """ SELECT ${History.TABLE}.* @@ -111,16 +83,6 @@ fun getLastReadMangaQuery() = ORDER BY max DESC """ -fun getTotalChapterMangaQuery() = - """ - SELECT ${Manga.TABLE}.* - FROM ${Manga.TABLE} - JOIN ${Chapter.TABLE} - ON ${Manga.TABLE}.${Manga.COL_ID} = ${Chapter.TABLE}.${Chapter.COL_MANGA_ID} - GROUP BY ${Manga.TABLE}.${Manga.COL_ID} - ORDER by COUNT(*) -""" - fun getLatestChapterMangaQuery() = """ SELECT ${Manga.TABLE}.*, MAX(${Chapter.TABLE}.${Chapter.COL_DATE_UPLOAD}) AS max diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaChapterHistoryGetResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaChapterHistoryGetResolver.kt deleted file mode 100644 index dbad8246eb..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaChapterHistoryGetResolver.kt +++ /dev/null @@ -1,51 +0,0 @@ -package eu.kanade.tachiyomi.data.database.resolvers - -import android.database.Cursor -import com.pushtorefresh.storio.sqlite.operations.get.DefaultGetResolver -import eu.kanade.tachiyomi.data.database.mappers.ChapterGetResolver -import eu.kanade.tachiyomi.data.database.mappers.HistoryGetResolver -import eu.kanade.tachiyomi.data.database.mappers.MangaGetResolver -import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory - -class MangaChapterHistoryGetResolver : DefaultGetResolver() { - companion object { - val INSTANCE = MangaChapterHistoryGetResolver() - } - - /** - * Manga get resolver - */ - private val mangaGetResolver = MangaGetResolver() - - /** - * Chapter get resolver - */ - private val chapterResolver = ChapterGetResolver() - - /** - * History get resolver - */ - private val historyGetResolver = HistoryGetResolver() - - /** - * Map correct objects from cursor result - */ - override fun mapFromCursor(cursor: Cursor): MangaChapterHistory { - // Get manga object - val manga = mangaGetResolver.mapFromCursor(cursor) - - // Get chapter object - val chapter = chapterResolver.mapFromCursor(cursor) - - // Get history object - val history = historyGetResolver.mapFromCursor(cursor) - - // Make certain column conflicts are dealt with - manga.id = chapter.manga_id - manga.url = cursor.getString(cursor.getColumnIndexOrThrow("mangaUrl")) - chapter.id = history.chapter_id - - // Return result - return MangaChapterHistory(manga, chapter, history) - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaTitlePutResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaTitlePutResolver.kt deleted file mode 100644 index 5ffa22befc..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaTitlePutResolver.kt +++ /dev/null @@ -1,32 +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.Manga -import eu.kanade.tachiyomi.data.database.tables.MangaTable - -class MangaTitlePutResolver : PutResolver() { - - override fun performPut(db: StorIOSQLite, manga: Manga) = db.inTransactionReturn { - val updateQuery = mapToUpdateQuery(manga) - val contentValues = mapToContentValues(manga) - - val numberOfRowsUpdated = db.lowLevel().update(updateQuery, contentValues) - PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) - } - - fun mapToUpdateQuery(manga: Manga) = UpdateQuery.builder() - .table(MangaTable.TABLE) - .where("${MangaTable.COL_ID} = ?") - .whereArgs(manga.id) - .build() - - fun mapToContentValues(manga: Manga) = - contentValuesOf( - MangaTable.COL_TITLE to manga.title, - ) -}