Ignore failures when updating metadata as part of library update

(cherry picked from commit 58860b51a211522e39a66dab1c9a3c3473824e64)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt
This commit is contained in:
arkon 2021-01-27 17:43:26 -05:00 committed by Jobobby04
parent 1eb8ee502e
commit 4f50fcadeb

View File

@ -49,6 +49,7 @@ import exh.source.mangaDexSourceIds
import exh.util.executeOnIO import exh.util.executeOnIO
import exh.util.nullIfBlank import exh.util.nullIfBlank
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
@ -227,24 +228,22 @@ class LibraryUpdateService(
val mangaList = getMangaToUpdate(intent, target) val mangaList = getMangaToUpdate(intent, target)
.sortedWith(rankingScheme[selectedScheme]) .sortedWith(rankingScheme[selectedScheme])
updateJob = ioScope.launch { val handler = CoroutineExceptionHandler { _, exception ->
try { Timber.e(exception)
when (target) { stopSelf(startId)
Target.CHAPTERS -> updateChapterList(mangaList) }
Target.COVERS -> updateCovers(mangaList) updateJob = ioScope.launch(handler) {
Target.TRACKING -> updateTrackings(mangaList) when (target) {
// SY --> Target.CHAPTERS -> updateChapterList(mangaList)
Target.SYNC_FOLLOWS -> syncFollows() Target.COVERS -> updateCovers(mangaList)
Target.PUSH_FAVORITES -> pushFavorites() Target.TRACKING -> updateTrackings(mangaList)
// SY <-- // SY -->
} Target.SYNC_FOLLOWS -> syncFollows()
} catch (e: Throwable) { Target.PUSH_FAVORITES -> pushFavorites()
Timber.e(e) // SY <--
stopSelf(startId)
} finally {
stopSelf(startId)
} }
} }
updateJob?.invokeOnCompletion { stopSelf(startId) }
return START_REDELIVER_INTENT return START_REDELIVER_INTENT
} }
@ -421,17 +420,22 @@ class LibraryUpdateService(
// Update manga details metadata in the background // Update manga details metadata in the background
if (preferences.autoUpdateMetadata()) { if (preferences.autoUpdateMetadata()) {
GlobalScope.launchIO { GlobalScope.launchIO {
val updatedManga = source.getMangaDetails(manga.toMangaInfo()) try {
val sManga = updatedManga.toSManga() val updatedManga = source.getMangaDetails(manga.toMangaInfo())
// Avoid "losing" existing cover val sManga = updatedManga.toSManga()
if (!sManga.thumbnail_url.isNullOrEmpty()) { // Avoid "losing" existing cover
manga.prepUpdateCover(coverCache, sManga, false) if (!sManga.thumbnail_url.isNullOrEmpty()) {
} else { manga.prepUpdateCover(coverCache, sManga, false)
sManga.thumbnail_url = manga.thumbnail_url } else {
} sManga.thumbnail_url = manga.thumbnail_url
}
manga.copyFrom(sManga) manga.copyFrom(sManga)
db.insertManga(manga).executeAsBlocking() db.insertManga(manga).executeAsBlocking()
} catch (e: Throwable) {
// Ignore errors and continue
Timber.e(e)
}
} }
} }