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 <kaiserbh@proton.me>
This commit is contained in:
parent
d6c4af89c4
commit
b1067b942e
1 changed files with 17 additions and 15 deletions
|
@ -57,22 +57,24 @@ class MangaRestorer(
|
||||||
backupManga: BackupManga,
|
backupManga: BackupManga,
|
||||||
backupCategories: List<BackupCategory>,
|
backupCategories: List<BackupCategory>,
|
||||||
) {
|
) {
|
||||||
val dbManga = findExistingManga(backupManga)
|
handler.await(inTransaction = true) {
|
||||||
val manga = backupManga.getMangaImpl()
|
val dbManga = findExistingManga(backupManga)
|
||||||
val restoredManga = if (dbManga == null) {
|
val manga = backupManga.getMangaImpl()
|
||||||
restoreNewManga(manga)
|
val restoredManga = if (dbManga == null) {
|
||||||
} else {
|
restoreNewManga(manga)
|
||||||
restoreExistingManga(manga, dbManga)
|
} else {
|
||||||
}
|
restoreExistingManga(manga, dbManga)
|
||||||
|
}
|
||||||
|
|
||||||
restoreMangaDetails(
|
restoreMangaDetails(
|
||||||
manga = restoredManga,
|
manga = restoredManga,
|
||||||
chapters = backupManga.chapters,
|
chapters = backupManga.chapters,
|
||||||
categories = backupManga.categories,
|
categories = backupManga.categories,
|
||||||
backupCategories = backupCategories,
|
backupCategories = backupCategories,
|
||||||
history = backupManga.history + backupManga.brokenHistory.map { it.toBackupHistory() },
|
history = backupManga.history + backupManga.brokenHistory.map { it.toBackupHistory() },
|
||||||
tracks = backupManga.tracking,
|
tracks = backupManga.tracking,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun findExistingManga(backupManga: BackupManga): Manga? {
|
private suspend fun findExistingManga(backupManga: BackupManga): Manga? {
|
||||||
|
|
Reference in a new issue