From b1067b942ef5c8d53e5ab838ef078789b9c0627a Mon Sep 17 00:00:00 2001 From: KaiserBh <41852205+KaiserBh@users.noreply.github.com> Date: Fri, 12 Jan 2024 10:22:46 +1100 Subject: [PATCH] Use transaction on restore to go brr. (#10375) refactor: use transaction to go brr. This improve the restore speed on fresh db and non fresh db. Signed-off-by: KaiserBh --- .../backup/restore/restorers/MangaRestorer.kt | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/restore/restorers/MangaRestorer.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/restore/restorers/MangaRestorer.kt index a09d5b1d73..f6b9455a32 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/restore/restorers/MangaRestorer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/restore/restorers/MangaRestorer.kt @@ -57,22 +57,24 @@ class MangaRestorer( backupManga: BackupManga, backupCategories: List, ) { - val dbManga = findExistingManga(backupManga) - val manga = backupManga.getMangaImpl() - val restoredManga = if (dbManga == null) { - restoreNewManga(manga) - } else { - restoreExistingManga(manga, dbManga) - } + handler.await(inTransaction = true) { + val dbManga = findExistingManga(backupManga) + val manga = backupManga.getMangaImpl() + val restoredManga = if (dbManga == null) { + restoreNewManga(manga) + } else { + restoreExistingManga(manga, dbManga) + } - restoreMangaDetails( - manga = restoredManga, - chapters = backupManga.chapters, - categories = backupManga.categories, - backupCategories = backupCategories, - history = backupManga.history + backupManga.brokenHistory.map { it.toBackupHistory() }, - tracks = backupManga.tracking, - ) + restoreMangaDetails( + manga = restoredManga, + chapters = backupManga.chapters, + categories = backupManga.categories, + backupCategories = backupCategories, + history = backupManga.history + backupManga.brokenHistory.map { it.toBackupHistory() }, + tracks = backupManga.tracking, + ) + } } private suspend fun findExistingManga(backupManga: BackupManga): Manga? {