mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-27 03:18:25 +01:00
Backup and Restore Excluded scanlators (#166)
* Backup and Restore Excluded scanlators * Improve performance * This looks better
This commit is contained in:
parent
38d6ab80ce
commit
e0deeb8008
@ -30,6 +30,10 @@ class MangaBackupCreator(
|
|||||||
// Entry for this manga
|
// Entry for this manga
|
||||||
val mangaObject = manga.toBackupManga()
|
val mangaObject = manga.toBackupManga()
|
||||||
|
|
||||||
|
mangaObject.excludedScanlators = handler.awaitList {
|
||||||
|
excluded_scanlatorsQueries.getExcludedScanlatorsByMangaId(manga.id)
|
||||||
|
}
|
||||||
|
|
||||||
if (options.chapters) {
|
if (options.chapters) {
|
||||||
// Backup all the chapters
|
// Backup all the chapters
|
||||||
handler.awaitList {
|
handler.awaitList {
|
||||||
|
@ -38,6 +38,7 @@ data class BackupManga(
|
|||||||
@ProtoNumber(105) var updateStrategy: UpdateStrategy = UpdateStrategy.ALWAYS_UPDATE,
|
@ProtoNumber(105) var updateStrategy: UpdateStrategy = UpdateStrategy.ALWAYS_UPDATE,
|
||||||
@ProtoNumber(106) var lastModifiedAt: Long = 0,
|
@ProtoNumber(106) var lastModifiedAt: Long = 0,
|
||||||
@ProtoNumber(107) var favoriteModifiedAt: Long? = null,
|
@ProtoNumber(107) var favoriteModifiedAt: Long? = null,
|
||||||
|
@ProtoNumber(108) var excludedScanlators: List<String> = emptyList(),
|
||||||
) {
|
) {
|
||||||
fun getMangaImpl(): Manga {
|
fun getMangaImpl(): Manga {
|
||||||
return Manga.create().copy(
|
return Manga.create().copy(
|
||||||
|
@ -73,6 +73,7 @@ class MangaRestorer(
|
|||||||
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,
|
||||||
|
excludedScanlators = backupManga.excludedScanlators,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,11 +265,13 @@ class MangaRestorer(
|
|||||||
backupCategories: List<BackupCategory>,
|
backupCategories: List<BackupCategory>,
|
||||||
history: List<BackupHistory>,
|
history: List<BackupHistory>,
|
||||||
tracks: List<BackupTracking>,
|
tracks: List<BackupTracking>,
|
||||||
|
excludedScanlators: List<String>,
|
||||||
): Manga {
|
): Manga {
|
||||||
restoreCategories(manga, categories, backupCategories)
|
restoreCategories(manga, categories, backupCategories)
|
||||||
restoreChapters(manga, chapters)
|
restoreChapters(manga, chapters)
|
||||||
restoreTracking(manga, tracks)
|
restoreTracking(manga, tracks)
|
||||||
restoreHistory(history)
|
restoreHistory(history)
|
||||||
|
restoreExcludedScanlators(manga, excludedScanlators)
|
||||||
updateManga.awaitUpdateFetchInterval(manga, now, currentFetchWindow)
|
updateManga.awaitUpdateFetchInterval(manga, now, currentFetchWindow)
|
||||||
return manga
|
return manga
|
||||||
}
|
}
|
||||||
@ -401,4 +404,25 @@ class MangaRestorer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun Track.forComparison() = this.copy(id = 0L, mangaId = 0L)
|
private fun Track.forComparison() = this.copy(id = 0L, mangaId = 0L)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restores the excluded scanlators for the manga.
|
||||||
|
*
|
||||||
|
* @param manga the manga whose excluded scanlators have to be restored.
|
||||||
|
* @param excludedScanlators the excluded scanlators to restore.
|
||||||
|
*/
|
||||||
|
private suspend fun restoreExcludedScanlators(manga: Manga, excludedScanlators: List<String>) {
|
||||||
|
if (excludedScanlators.isEmpty()) return
|
||||||
|
val existingExcludedScanlators = handler.awaitList {
|
||||||
|
excluded_scanlatorsQueries.getExcludedScanlatorsByMangaId(manga.id)
|
||||||
|
}
|
||||||
|
val toInsert = excludedScanlators.filter { it !in existingExcludedScanlators }
|
||||||
|
if (toInsert.isNotEmpty()) {
|
||||||
|
handler.await {
|
||||||
|
toInsert.forEach {
|
||||||
|
excluded_scanlatorsQueries.insert(manga.id, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user