mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Do library checks from up to 5 sources concurrently
(cherry picked from commit f853158e6b)
# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt
			
			
This commit is contained in:
		| @@ -309,41 +309,51 @@ class LibraryUpdateService( | ||||
|  | ||||
|         // Emit each manga and update it sequentially. | ||||
|         return Observable.from(mangaToUpdate) | ||||
|             // Notify manga that will update. | ||||
|             .doOnNext { showProgressNotification(it, count.andIncrement, mangaToUpdate.size) } | ||||
|             // Update the chapters of the manga. | ||||
|             .concatMap { manga -> | ||||
|                 if (manga.source in LIBRARY_UPDATE_EXCLUDED_SOURCES) { | ||||
|                     // Ignore EXH manga, updating chapters for every manga will get you banned | ||||
|                     Observable.empty() | ||||
|                 } else { | ||||
|                     updateManga(manga) | ||||
|                         // If there's any error, return empty update and continue. | ||||
|                         .onErrorReturn { | ||||
|                             failedUpdates.add(manga) | ||||
|                             Pair(emptyList(), emptyList()) | ||||
|                         } | ||||
|                         // Filter out mangas without new chapters (or failed). | ||||
|                         .filter { pair -> pair.first.isNotEmpty() } | ||||
|                         .doOnNext { | ||||
|                             if (downloadNew && ( | ||||
|                                 categoriesToDownload.isEmpty() || | ||||
|                                     manga.category in categoriesToDownload | ||||
|                                 ) | ||||
|                             ) { | ||||
|                                 downloadChapters(manga, it.first) | ||||
|                                 hasDownloads = true | ||||
|             // Update the chapters of the manga concurrently from 5 different sources | ||||
|             .groupBy { it.source } | ||||
|             .flatMap( | ||||
|                 { bySource -> | ||||
|                     bySource | ||||
|                         // Notify manga that will update. | ||||
|                         .doOnNext { showProgressNotification(it, count.andIncrement, mangaToUpdate.size) } | ||||
|                         .concatMap { manga -> | ||||
|                             if (manga.source in LIBRARY_UPDATE_EXCLUDED_SOURCES) { | ||||
|                                 // Ignore EXH manga, updating chapters for every manga will get you banned | ||||
|                                 Observable.empty() | ||||
|                             } else { | ||||
|                                 updateManga(manga) | ||||
|                                     // If there's any error, return empty update and continue. | ||||
|                                     .onErrorReturn { | ||||
|                                         failedUpdates.add(manga) | ||||
|                                         Pair(emptyList(), emptyList()) | ||||
|                                     } | ||||
|                                     // Filter out mangas without new chapters (or failed). | ||||
|                                     .filter { pair -> pair.first.isNotEmpty() } | ||||
|                                     .doOnNext { | ||||
|                                         if (downloadNew && ( | ||||
|                                             categoriesToDownload.isEmpty() || | ||||
|                                                 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. | ||||
|                     .map { | ||||
|                         Pair( | ||||
|                             manga, | ||||
|                             (it.first.sortedByDescending { ch -> ch.source_order }.toTypedArray()) | ||||
|                         ) | ||||
|                     } | ||||
|             } | ||||
|                 }, | ||||
|                 5 | ||||
|             ) | ||||
|             // Add manga with new chapters to the list. | ||||
|             .doOnNext { manga -> | ||||
|                 // Add to the list | ||||
| @@ -403,21 +413,28 @@ class LibraryUpdateService( | ||||
|  | ||||
|         // Emit each manga and update it sequentially. | ||||
|         return Observable.from(mangaToUpdate) | ||||
|             // Notify manga that will update. | ||||
|             .doOnNext { showProgressNotification(it, count.andIncrement, mangaToUpdate.size) } | ||||
|             // Update the details of the manga. | ||||
|             .concatMap { manga -> | ||||
|                 val source = sourceManager.get(manga.source) as? HttpSource | ||||
|                     ?: return@concatMap Observable.empty<LibraryManga>() | ||||
|             // Update the details of the manga concurrently from 5 different sources | ||||
|             .groupBy { it.source } | ||||
|             .flatMap( | ||||
|                 { bySource -> | ||||
|                     bySource | ||||
|                         // 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) | ||||
|                     .map { networkManga -> | ||||
|                         manga.copyFrom(networkManga) | ||||
|                         db.insertManga(manga).executeAsBlocking() | ||||
|                         manga | ||||
|                     } | ||||
|                     .onErrorReturn { manga } | ||||
|             } | ||||
|                             source.fetchMangaDetails(manga) | ||||
|                                 .map { networkManga -> | ||||
|                                     manga.copyFrom(networkManga) | ||||
|                                     db.insertManga(manga).executeAsBlocking() | ||||
|                                     manga | ||||
|                                 } | ||||
|                                 .onErrorReturn { manga } | ||||
|                         } | ||||
|                 }, | ||||
|                 5 | ||||
|             ) | ||||
|             .doOnCompleted { | ||||
|                 cancelProgressNotification() | ||||
|             } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user