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() val dbChapters = databaseHelper.getChapters(manga).executeAsBlocking()
chapters.forEach { chapter -> chapters.forEach { chapter ->
val pos = dbChapters.indexOfFirst { it.url == chapter.url } val dbChapter = dbChapters.find { it.url == chapter.url }
if (pos != -1) { if (dbChapter != null) {
val dbChapter = dbChapters[pos]
chapter.id = dbChapter.id chapter.id = dbChapter.id
chapter.copyFrom(dbChapter) chapter.copyFrom(dbChapter)
if (dbChapter.read && !chapter.read) { 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 }) val newChapters = chapters.groupBy { it.id != null }
insertChapters(chapters.filter { it.id == null }) newChapters[true]?.let { updateChapters(it) }
newChapters[false]?.let { insertChapters(it) }
} }
// SY --> // SY -->

View File

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