mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 22:39:18 +01:00
Move DB transaction blocks to only the DB portions of restore logic
This commit is contained in:
parent
6b3b98cf57
commit
63f3180dff
@ -230,41 +230,39 @@ class BackupRestoreService : Service() {
|
|||||||
private fun restoreCategories(categoriesJson: JsonElement) {
|
private fun restoreCategories(categoriesJson: JsonElement) {
|
||||||
db.inTransaction {
|
db.inTransaction {
|
||||||
backupManager.restoreCategories(categoriesJson.asJsonArray)
|
backupManager.restoreCategories(categoriesJson.asJsonArray)
|
||||||
|
|
||||||
restoreProgress += 1
|
|
||||||
showRestoreProgress(restoreProgress, restoreAmount, getString(R.string.categories))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restoreProgress += 1
|
||||||
|
showRestoreProgress(restoreProgress, restoreAmount, getString(R.string.categories))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun restoreManga(mangaJson: JsonObject) {
|
private fun restoreManga(mangaJson: JsonObject) {
|
||||||
db.inTransaction {
|
val manga = backupManager.parser.fromJson<MangaImpl>(mangaJson.get(MANGA))
|
||||||
val manga = backupManager.parser.fromJson<MangaImpl>(mangaJson.get(MANGA))
|
val chapters = backupManager.parser.fromJson<List<ChapterImpl>>(
|
||||||
val chapters = backupManager.parser.fromJson<List<ChapterImpl>>(
|
mangaJson.get(CHAPTERS)
|
||||||
mangaJson.get(CHAPTERS)
|
?: JsonArray()
|
||||||
?: JsonArray()
|
)
|
||||||
)
|
val categories = backupManager.parser.fromJson<List<String>>(
|
||||||
val categories = backupManager.parser.fromJson<List<String>>(
|
mangaJson.get(CATEGORIES)
|
||||||
mangaJson.get(CATEGORIES)
|
?: JsonArray()
|
||||||
?: JsonArray()
|
)
|
||||||
)
|
val history = backupManager.parser.fromJson<List<DHistory>>(
|
||||||
val history = backupManager.parser.fromJson<List<DHistory>>(
|
mangaJson.get(HISTORY)
|
||||||
mangaJson.get(HISTORY)
|
?: JsonArray()
|
||||||
?: JsonArray()
|
)
|
||||||
)
|
val tracks = backupManager.parser.fromJson<List<TrackImpl>>(
|
||||||
val tracks = backupManager.parser.fromJson<List<TrackImpl>>(
|
mangaJson.get(TRACK)
|
||||||
mangaJson.get(TRACK)
|
?: JsonArray()
|
||||||
?: JsonArray()
|
)
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
restoreMangaData(manga, chapters, categories, history, tracks)
|
restoreMangaData(manga, chapters, categories, history, tracks)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
errors.add(Date() to "${manga.title} - ${getString(R.string.source_not_found)}")
|
errors.add(Date() to "${manga.title} - ${getString(R.string.source_not_found)}")
|
||||||
}
|
|
||||||
|
|
||||||
restoreProgress += 1
|
|
||||||
showRestoreProgress(restoreProgress, restoreAmount, manga.title)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restoreProgress += 1
|
||||||
|
showRestoreProgress(restoreProgress, restoreAmount, manga.title)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -287,14 +285,16 @@ class BackupRestoreService : Service() {
|
|||||||
val source = backupManager.sourceManager.getOrStub(manga.source)
|
val source = backupManager.sourceManager.getOrStub(manga.source)
|
||||||
val dbManga = backupManager.getMangaFromDatabase(manga)
|
val dbManga = backupManager.getMangaFromDatabase(manga)
|
||||||
|
|
||||||
if (dbManga == null) {
|
db.inTransaction {
|
||||||
// Manga not in database
|
if (dbManga == null) {
|
||||||
restoreMangaFetch(source, manga, chapters, categories, history, tracks)
|
// Manga not in database
|
||||||
} else { // Manga in database
|
restoreMangaFetch(source, manga, chapters, categories, history, tracks)
|
||||||
// Copy information from manga already in database
|
} else { // Manga in database
|
||||||
backupManager.restoreMangaNoFetch(manga, dbManga)
|
// Copy information from manga already in database
|
||||||
// Fetch rest of manga information
|
backupManager.restoreMangaNoFetch(manga, dbManga)
|
||||||
restoreMangaNoFetch(source, manga, chapters, categories, history, tracks)
|
// Fetch rest of manga information
|
||||||
|
restoreMangaNoFetch(source, manga, chapters, categories, history, tracks)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user