Only update chapter/viewer flags for library manga instead of everything (addresses #5809)

This commit is contained in:
arkon 2021-08-28 12:02:08 -04:00
parent 925f71af15
commit 7fa80ae556
3 changed files with 10 additions and 32 deletions

View File

@ -81,7 +81,7 @@ interface MangaQueries : DbProvider {
fun updateChapterFlags(manga: List<Manga>) = db.put() fun updateChapterFlags(manga: List<Manga>) = db.put()
.objects(manga) .objects(manga)
.withPutResolver(MangaFlagsPutResolver(MangaTable.COL_CHAPTER_FLAGS, Manga::chapter_flags, true)) .withPutResolver(MangaFlagsPutResolver(MangaTable.COL_CHAPTER_FLAGS, Manga::chapter_flags))
.prepare() .prepare()
fun updateViewerFlags(manga: Manga) = db.put() fun updateViewerFlags(manga: Manga) = db.put()
@ -91,7 +91,7 @@ interface MangaQueries : DbProvider {
fun updateViewerFlags(manga: List<Manga>) = db.put() fun updateViewerFlags(manga: List<Manga>) = db.put()
.objects(manga) .objects(manga)
.withPutResolver(MangaFlagsPutResolver(MangaTable.COL_VIEWER, Manga::viewer_flags, true)) .withPutResolver(MangaFlagsPutResolver(MangaTable.COL_VIEWER, Manga::viewer_flags))
.prepare() .prepare()
fun updateNextUpdated(manga: Manga) = db.put() fun updateNextUpdated(manga: Manga) = db.put()

View File

@ -27,9 +27,7 @@ class HistoryLastReadPutResolver : HistoryPutResolver() {
.build() .build()
) )
val putResult: PutResult cursor.use { putCursor ->
putResult = cursor.use { putCursor ->
if (putCursor.count == 0) { if (putCursor.count == 0) {
val insertQuery = mapToInsertQuery(history) val insertQuery = mapToInsertQuery(history)
val insertedId = db.lowLevel().insert(insertQuery, mapToContentValues(history)) val insertedId = db.lowLevel().insert(insertQuery, mapToContentValues(history))
@ -39,25 +37,15 @@ class HistoryLastReadPutResolver : HistoryPutResolver() {
PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table())
} }
} }
putResult
} }
/**
* Creates update query
* @param obj history object
*/
override fun mapToUpdateQuery(obj: History) = UpdateQuery.builder() override fun mapToUpdateQuery(obj: History) = UpdateQuery.builder()
.table(HistoryTable.TABLE) .table(HistoryTable.TABLE)
.where("${HistoryTable.COL_CHAPTER_ID} = ?") .where("${HistoryTable.COL_CHAPTER_ID} = ?")
.whereArgs(obj.chapter_id) .whereArgs(obj.chapter_id)
.build() .build()
/** private fun mapToUpdateContentValues(history: History) =
* Create content query
* @param history object
*/
fun mapToUpdateContentValues(history: History) =
contentValuesOf( contentValuesOf(
HistoryTable.COL_LAST_READ to history.last_read HistoryTable.COL_LAST_READ to history.last_read
) )

View File

@ -10,7 +10,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.database.tables.MangaTable import eu.kanade.tachiyomi.data.database.tables.MangaTable
import kotlin.reflect.KProperty1 import kotlin.reflect.KProperty1
class MangaFlagsPutResolver(private val colName: String, private val fieldGetter: KProperty1<Manga, Int>, private val updateAll: Boolean = false) : PutResolver<Manga>() { class MangaFlagsPutResolver(private val colName: String, private val fieldGetter: KProperty1<Manga, Int>) : PutResolver<Manga>() {
override fun performPut(db: StorIOSQLite, manga: Manga) = db.inTransactionReturn { override fun performPut(db: StorIOSQLite, manga: Manga) = db.inTransactionReturn {
val updateQuery = mapToUpdateQuery(manga) val updateQuery = mapToUpdateQuery(manga)
@ -20,21 +20,11 @@ class MangaFlagsPutResolver(private val colName: String, private val fieldGetter
PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table())
} }
fun mapToUpdateQuery(manga: Manga): UpdateQuery { fun mapToUpdateQuery(manga: Manga) = UpdateQuery.builder()
val builder = UpdateQuery.builder()
return if (updateAll) {
builder
.table(MangaTable.TABLE)
.build()
} else {
builder
.table(MangaTable.TABLE) .table(MangaTable.TABLE)
.where("${MangaTable.COL_ID} = ?") .where("${MangaTable.COL_ID} = ?")
.whereArgs(manga.id) .whereArgs(manga.id)
.build() .build()
}
}
fun mapToContentValues(manga: Manga) = fun mapToContentValues(manga: Manga) =
contentValuesOf( contentValuesOf(