mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-30 04:54:55 -05:00
Do library checks from up to 5 sources concurrently
This commit is contained in:
parent
c9035b5df9
commit
f853158e6b
1 changed files with 60 additions and 43 deletions
|
@ -308,36 +308,46 @@ class LibraryUpdateService(
|
||||||
|
|
||||||
// Emit each manga and update it sequentially.
|
// Emit each manga and update it sequentially.
|
||||||
return Observable.from(mangaToUpdate)
|
return Observable.from(mangaToUpdate)
|
||||||
// Notify manga that will update.
|
// Update the chapters of the manga concurrently from 5 different sources
|
||||||
.doOnNext { showProgressNotification(it, count.andIncrement, mangaToUpdate.size) }
|
.groupBy { it.source }
|
||||||
// Update the chapters of the manga.
|
.flatMap(
|
||||||
.concatMap { manga ->
|
{ bySource ->
|
||||||
updateManga(manga)
|
bySource
|
||||||
// If there's any error, return empty update and continue.
|
// Notify manga that will update.
|
||||||
.onErrorReturn {
|
.doOnNext { showProgressNotification(it, count.andIncrement, mangaToUpdate.size) }
|
||||||
failedUpdates.add(manga)
|
.concatMap { manga ->
|
||||||
Pair(emptyList(), emptyList())
|
updateManga(manga)
|
||||||
}
|
// If there's any error, return empty update and continue.
|
||||||
// Filter out mangas without new chapters (or failed).
|
.onErrorReturn {
|
||||||
.filter { pair -> pair.first.isNotEmpty() }
|
failedUpdates.add(manga)
|
||||||
.doOnNext {
|
Pair(emptyList(), emptyList())
|
||||||
if (downloadNew && (
|
}
|
||||||
categoriesToDownload.isEmpty() ||
|
// Filter out mangas without new chapters (or failed).
|
||||||
manga.category in categoriesToDownload
|
.filter { pair -> pair.first.isNotEmpty() }
|
||||||
)
|
.doOnNext {
|
||||||
) {
|
if (downloadNew && (
|
||||||
downloadChapters(manga, it.first)
|
categoriesToDownload.isEmpty() ||
|
||||||
hasDownloads = true
|
manga.category in categoriesToDownload
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
downloadChapters(manga, it.first)
|
||||||
|
hasDownloads = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Convert to the manga that contains new chapters.
|
||||||
|
.map {
|
||||||
|
Pair(
|
||||||
|
manga,
|
||||||
|
(
|
||||||
|
it.first.sortedByDescending { ch -> ch.source_order }
|
||||||
|
.toTypedArray()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
// Convert to the manga that contains new chapters.
|
5
|
||||||
.map {
|
)
|
||||||
Pair(
|
|
||||||
manga,
|
|
||||||
(it.first.sortedByDescending { ch -> ch.source_order }.toTypedArray())
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Add manga with new chapters to the list.
|
// Add manga with new chapters to the list.
|
||||||
.doOnNext { manga ->
|
.doOnNext { manga ->
|
||||||
// Add to the list
|
// Add to the list
|
||||||
|
@ -397,21 +407,28 @@ class LibraryUpdateService(
|
||||||
|
|
||||||
// Emit each manga and update it sequentially.
|
// Emit each manga and update it sequentially.
|
||||||
return Observable.from(mangaToUpdate)
|
return Observable.from(mangaToUpdate)
|
||||||
// Notify manga that will update.
|
// Update the details of the manga concurrently from 5 different sources
|
||||||
.doOnNext { showProgressNotification(it, count.andIncrement, mangaToUpdate.size) }
|
.groupBy { it.source }
|
||||||
// Update the details of the manga.
|
.flatMap(
|
||||||
.concatMap { manga ->
|
{ bySource ->
|
||||||
val source = sourceManager.get(manga.source) as? HttpSource
|
bySource
|
||||||
?: return@concatMap Observable.empty<LibraryManga>()
|
// Notify manga that will update.
|
||||||
|
.doOnNext { showProgressNotification(it, count.andIncrement, mangaToUpdate.size) }
|
||||||
|
.concatMap { manga ->
|
||||||
|
val source = sourceManager.get(manga.source) as? HttpSource
|
||||||
|
?: return@concatMap Observable.empty<LibraryManga>()
|
||||||
|
|
||||||
source.fetchMangaDetails(manga)
|
source.fetchMangaDetails(manga)
|
||||||
.map { networkManga ->
|
.map { networkManga ->
|
||||||
manga.copyFrom(networkManga)
|
manga.copyFrom(networkManga)
|
||||||
db.insertManga(manga).executeAsBlocking()
|
db.insertManga(manga).executeAsBlocking()
|
||||||
manga
|
manga
|
||||||
}
|
}
|
||||||
.onErrorReturn { manga }
|
.onErrorReturn { manga }
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
5
|
||||||
|
)
|
||||||
.doOnCompleted {
|
.doOnCompleted {
|
||||||
cancelProgressNotification()
|
cancelProgressNotification()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue