From cb1ea6f57113eaa5ef20a8c8ee38e5c7d27d795b Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 9 Feb 2021 17:44:22 -0500 Subject: [PATCH] Clean up LibraryUpdateService a bit (cherry picked from commit 5af68186d6de62a5746d758977a9ca834c25f547) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt --- .../data/library/LibraryUpdateService.kt | 39 +++++++------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index c77e1fe33..858d2a8af 100755 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -342,51 +342,40 @@ class LibraryUpdateService( async { semaphore.withPermit { mangaInSource - .map { manga -> + .onEach { manga -> if (updateJob?.isActive != true) { return@async } - // Notify manga that will update. notifier.showProgressNotification(manga, progressCount.andIncrement, mangaToUpdate.size) - // Update the chapters of the manga try { - val newChapters = updateManga(manga).first - Pair(manga, newChapters) + val (newChapters, _) = updateManga(manga) + + if (newChapters.isNotEmpty()) { + if (manga.shouldDownloadNewChapters(db, preferences)) { + downloadChapters(manga, newChapters) + hasDownloads = true + } + + // Convert to the manga that contains new chapters + newUpdates.add(manga to newChapters.sortedByDescending { ch -> ch.source_order } + .toTypedArray()) + } } catch (e: Throwable) { - // If there's any error, return empty update and continue. val errorMessage = if (e is NoChaptersException) { getString(R.string.no_chapters_error) } else { e.message } - failedUpdates.add(Pair(manga, errorMessage)) - Pair(manga, emptyList()) + failedUpdates.add(manga to errorMessage) } } - // Filter out mangas without new chapters (or failed). - .filter { (_, newChapters) -> newChapters.isNotEmpty() } - .forEach { (manga, newChapters) -> - if (manga.shouldDownloadNewChapters(db, preferences)) { - downloadChapters(manga, newChapters) - hasDownloads = true - } - - // Convert to the manga that contains new chapters. - newUpdates.add( - Pair( - manga, - newChapters.sortedByDescending { ch -> ch.source_order }.toTypedArray() - ) - ) - } } } }.awaitAll() } - // Notify result of the overall update. notifier.cancelProgressNotification() if (newUpdates.isNotEmpty()) {