Restore offline optimization

Should make restore offline faster when data is already there
This commit is contained in:
Jobobby04 2021-02-04 17:06:07 -05:00
parent e629703afd
commit fc6d9aaf51
2 changed files with 8 additions and 8 deletions

View File

@ -440,9 +440,8 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
val dbChapters = databaseHelper.getChapters(manga).executeAsBlocking()
chapters.forEach { chapter ->
val pos = dbChapters.indexOfFirst { it.url == chapter.url }
if (pos != -1) {
val dbChapter = dbChapters[pos]
val dbChapter = dbChapters.find { it.url == chapter.url }
if (dbChapter != null) {
chapter.id = dbChapter.id
chapter.copyFrom(dbChapter)
if (dbChapter.read && !chapter.read) {
@ -456,10 +455,11 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
}
}
}
chapters.map { it.manga_id = manga.id }
chapters.forEach { it.manga_id = manga.id }
updateChapters(chapters.filter { it.id != null })
insertChapters(chapters.filter { it.id == null })
val newChapters = chapters.groupBy { it.id != null }
newChapters[true]?.let { updateChapters(it) }
newChapters[false]?.let { insertChapters(it) }
}
// SY -->

View File

@ -21,8 +21,8 @@ class ChapterBackupPutResolver : PutResolver<Chapter>() {
fun mapToUpdateQuery(chapter: Chapter) = UpdateQuery.builder()
.table(ChapterTable.TABLE)
.where("${ChapterTable.COL_URL} = ?")
.whereArgs(chapter.url)
.where("${ChapterTable.COL_ID} = ?")
.whereArgs(chapter.id)
.build()
fun mapToContentValues(chapter: Chapter) =