Minor optimizations for restoring full backups

Based on fc6d9aaf51

(cherry picked from commit 2e9ef373f339257767f54fe3a6d3e51526cac683)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt
This commit is contained in:
arkon 2021-02-06 09:32:00 -05:00 committed by Jobobby04
parent 6be485ea79
commit bd8084c565

View File

@ -301,7 +301,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
*/ */
internal fun restoreCategoriesForManga(manga: Manga, categories: List<Int>, backupCategories: List<BackupCategory>) { internal fun restoreCategoriesForManga(manga: Manga, categories: List<Int>, backupCategories: List<BackupCategory>) {
val dbCategories = databaseHelper.getCategories().executeAsBlocking() val dbCategories = databaseHelper.getCategories().executeAsBlocking()
val mangaCategoriesToUpdate = mutableListOf<MangaCategory>() val mangaCategoriesToUpdate = ArrayList<MangaCategory>(categories.size)
categories.forEach { backupCategoryOrder -> categories.forEach { backupCategoryOrder ->
backupCategories.firstOrNull { backupCategories.firstOrNull {
it.order == backupCategoryOrder it.order == backupCategoryOrder
@ -328,7 +328,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
*/ */
internal fun restoreHistoryForManga(history: List<BackupHistory>) { internal fun restoreHistoryForManga(history: List<BackupHistory>) {
// List containing history to be updated // List containing history to be updated
val historyToBeUpdated = mutableListOf<History>() val historyToBeUpdated = ArrayList<History>(history.size)
for ((url, lastRead) in history) { for ((url, lastRead) in history) {
val dbHistory = databaseHelper.getHistoryByChapterUrl(url).executeAsBlocking() val dbHistory = databaseHelper.getHistoryByChapterUrl(url).executeAsBlocking()
// Check if history already in database and update // Check if history already in database and update
@ -412,9 +412,8 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
} }
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) {
@ -427,12 +426,13 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
chapter.bookmark = dbChapter.bookmark chapter.bookmark = dbChapter.bookmark
} }
} }
}
// Filter the chapters that couldn't be found.
chapters.filter { it.id != null }
chapters.map { it.manga_id = manga.id }
updateChapters(chapters) chapter.manga_id = manga.id
}
// Filter the chapters that couldn't be found.
updateChapters(chapters.filter { it.id != null })
return true return true
} }
@ -454,8 +454,9 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
chapter.bookmark = dbChapter.bookmark chapter.bookmark = dbChapter.bookmark
} }
} }
chapter.manga_id = manga.id
} }
chapters.forEach { it.manga_id = manga.id }
val newChapters = chapters.groupBy { it.id != null } val newChapters = chapters.groupBy { it.id != null }
newChapters[true]?.let { updateChapters(it) } newChapters[true]?.let { updateChapters(it) }