Cleanup library update a bit
This commit is contained in:
parent
a29ddaaf1c
commit
4e8142b5b8
@ -361,45 +361,45 @@ class LibraryUpdateService(
|
|||||||
withIOContext {
|
withIOContext {
|
||||||
mangaToUpdate.groupBy { it.source }
|
mangaToUpdate.groupBy { it.source }
|
||||||
.filterNot { it.key in LIBRARY_UPDATE_EXCLUDED_SOURCES }
|
.filterNot { it.key in LIBRARY_UPDATE_EXCLUDED_SOURCES }
|
||||||
.values.map { mangaInSource ->
|
.values
|
||||||
|
.map { mangaInSource ->
|
||||||
async {
|
async {
|
||||||
semaphore.withPermit {
|
semaphore.withPermit {
|
||||||
mangaInSource
|
mangaInSource.forEach { manga ->
|
||||||
.onEach { manga ->
|
if (updateJob?.isActive != true) {
|
||||||
if (updateJob?.isActive != true) {
|
return@async
|
||||||
return@async
|
|
||||||
}
|
|
||||||
|
|
||||||
notifier.showProgressNotification(manga, progressCount.andIncrement, mangaToUpdate.size)
|
|
||||||
|
|
||||||
try {
|
|
||||||
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) {
|
|
||||||
val errorMessage = if (e is NoChaptersException) {
|
|
||||||
getString(R.string.no_chapters_error)
|
|
||||||
} else {
|
|
||||||
e.message
|
|
||||||
}
|
|
||||||
failedUpdates.add(manga to errorMessage)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preferences.autoUpdateTrackers()) {
|
|
||||||
updateTrackings(manga, loggedServices)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notifier.showProgressNotification(manga, progressCount.andIncrement, mangaToUpdate.size)
|
||||||
|
|
||||||
|
try {
|
||||||
|
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) {
|
||||||
|
val errorMessage = if (e is NoChaptersException) {
|
||||||
|
getString(R.string.no_chapters_error)
|
||||||
|
} else {
|
||||||
|
e.message
|
||||||
|
}
|
||||||
|
failedUpdates.add(manga to errorMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preferences.autoUpdateTrackers()) {
|
||||||
|
updateTrackings(manga, loggedServices)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.awaitAll()
|
}.awaitAll()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user