From 7fa80ae556de6492cbb60c10a3d751ade5c14c72 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 28 Aug 2021 12:02:08 -0400 Subject: [PATCH] Only update chapter/viewer flags for library manga instead of everything (addresses #5809) --- .../data/database/queries/MangaQueries.kt | 4 ++-- .../resolvers/HistoryLastReadPutResolver.kt | 16 ++------------ .../resolvers/MangaFlagsPutResolver.kt | 22 +++++-------------- 3 files changed, 10 insertions(+), 32 deletions(-) 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 48538cfc1b..667720aa0b 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 @@ -81,7 +81,7 @@ interface MangaQueries : DbProvider { fun updateChapterFlags(manga: List) = db.put() .objects(manga) - .withPutResolver(MangaFlagsPutResolver(MangaTable.COL_CHAPTER_FLAGS, Manga::chapter_flags, true)) + .withPutResolver(MangaFlagsPutResolver(MangaTable.COL_CHAPTER_FLAGS, Manga::chapter_flags)) .prepare() fun updateViewerFlags(manga: Manga) = db.put() @@ -91,7 +91,7 @@ interface MangaQueries : DbProvider { fun updateViewerFlags(manga: List) = db.put() .objects(manga) - .withPutResolver(MangaFlagsPutResolver(MangaTable.COL_VIEWER, Manga::viewer_flags, true)) + .withPutResolver(MangaFlagsPutResolver(MangaTable.COL_VIEWER, Manga::viewer_flags)) .prepare() fun updateNextUpdated(manga: Manga) = db.put() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/HistoryLastReadPutResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/HistoryLastReadPutResolver.kt index 07b883b455..8546c7e55d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/HistoryLastReadPutResolver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/HistoryLastReadPutResolver.kt @@ -27,9 +27,7 @@ class HistoryLastReadPutResolver : HistoryPutResolver() { .build() ) - val putResult: PutResult - - putResult = cursor.use { putCursor -> + cursor.use { putCursor -> if (putCursor.count == 0) { val insertQuery = mapToInsertQuery(history) val insertedId = db.lowLevel().insert(insertQuery, mapToContentValues(history)) @@ -39,25 +37,15 @@ class HistoryLastReadPutResolver : HistoryPutResolver() { PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) } } - - putResult } - /** - * Creates update query - * @param obj history object - */ override fun mapToUpdateQuery(obj: History) = UpdateQuery.builder() .table(HistoryTable.TABLE) .where("${HistoryTable.COL_CHAPTER_ID} = ?") .whereArgs(obj.chapter_id) .build() - /** - * Create content query - * @param history object - */ - fun mapToUpdateContentValues(history: History) = + private fun mapToUpdateContentValues(history: History) = contentValuesOf( HistoryTable.COL_LAST_READ to history.last_read ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaFlagsPutResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaFlagsPutResolver.kt index e19a4c889e..7437e932ec 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaFlagsPutResolver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaFlagsPutResolver.kt @@ -10,7 +10,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.tables.MangaTable import kotlin.reflect.KProperty1 -class MangaFlagsPutResolver(private val colName: String, private val fieldGetter: KProperty1, private val updateAll: Boolean = false) : PutResolver() { +class MangaFlagsPutResolver(private val colName: String, private val fieldGetter: KProperty1) : PutResolver() { override fun performPut(db: StorIOSQLite, manga: Manga) = db.inTransactionReturn { val updateQuery = mapToUpdateQuery(manga) @@ -20,21 +20,11 @@ class MangaFlagsPutResolver(private val colName: String, private val fieldGetter PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) } - fun mapToUpdateQuery(manga: Manga): UpdateQuery { - val builder = UpdateQuery.builder() - - return if (updateAll) { - builder - .table(MangaTable.TABLE) - .build() - } else { - builder - .table(MangaTable.TABLE) - .where("${MangaTable.COL_ID} = ?") - .whereArgs(manga.id) - .build() - } - } + fun mapToUpdateQuery(manga: Manga) = UpdateQuery.builder() + .table(MangaTable.TABLE) + .where("${MangaTable.COL_ID} = ?") + .whereArgs(manga.id) + .build() fun mapToContentValues(manga: Manga) = contentValuesOf(