Update trackers in parallel, update manga metadata asynchronously
(cherry picked from commit 04a993c99788076c692acd904c3dd65720217916)
This commit is contained in:
parent
dd3b8c7967
commit
788ed6dcc9
@ -50,7 +50,10 @@ import exh.util.nullIfBlank
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.MainScope
|
import kotlinx.coroutines.MainScope
|
||||||
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.awaitAll
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
|
import kotlinx.coroutines.supervisorScope
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
@ -323,7 +326,7 @@ class LibraryUpdateService(
|
|||||||
*/
|
*/
|
||||||
suspend fun updateChapterList(mangaToUpdate: List<LibraryManga>) {
|
suspend fun updateChapterList(mangaToUpdate: List<LibraryManga>) {
|
||||||
// Initialize the variables holding the progress of the updates.
|
// Initialize the variables holding the progress of the updates.
|
||||||
val count = AtomicInteger(0)
|
val progressCount = AtomicInteger(0)
|
||||||
// List containing new updates
|
// List containing new updates
|
||||||
val newUpdates = mutableListOf<Pair<LibraryManga, Array<Chapter>>>()
|
val newUpdates = mutableListOf<Pair<LibraryManga, Array<Chapter>>>()
|
||||||
// List containing failed updates
|
// List containing failed updates
|
||||||
@ -334,7 +337,7 @@ class LibraryUpdateService(
|
|||||||
mangaToUpdate
|
mangaToUpdate
|
||||||
.mapNotNull { manga ->
|
.mapNotNull { manga ->
|
||||||
// Notify manga that will update.
|
// Notify manga that will update.
|
||||||
notifier.showProgressNotification(manga, count.andIncrement, mangaToUpdate.size)
|
notifier.showProgressNotification(manga, progressCount.andIncrement, mangaToUpdate.size)
|
||||||
|
|
||||||
// SY -->
|
// SY -->
|
||||||
if (manga.source in LIBRARY_UPDATE_EXCLUDED_SOURCES) return@mapNotNull null
|
if (manga.source in LIBRARY_UPDATE_EXCLUDED_SOURCES) return@mapNotNull null
|
||||||
@ -412,6 +415,7 @@ class LibraryUpdateService(
|
|||||||
|
|
||||||
// Update manga details metadata in the background
|
// Update manga details metadata in the background
|
||||||
if (preferences.autoUpdateMetadata()) {
|
if (preferences.autoUpdateMetadata()) {
|
||||||
|
scope.async {
|
||||||
val updatedManga = source.getMangaDetails(manga.toMangaInfo())
|
val updatedManga = source.getMangaDetails(manga.toMangaInfo())
|
||||||
val sManga = updatedManga.toSManga()
|
val sManga = updatedManga.toSManga()
|
||||||
// Avoid "losing" existing cover
|
// Avoid "losing" existing cover
|
||||||
@ -424,6 +428,7 @@ class LibraryUpdateService(
|
|||||||
manga.copyFrom(sManga)
|
manga.copyFrom(sManga)
|
||||||
db.insertManga(manga).executeAsBlocking()
|
db.insertManga(manga).executeAsBlocking()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
scope.launchIO {
|
scope.launchIO {
|
||||||
if (source is MangaDex && trackManager.mdList.isLogged) {
|
if (source is MangaDex && trackManager.mdList.isLogged) {
|
||||||
@ -449,10 +454,10 @@ class LibraryUpdateService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun updateCovers(mangaToUpdate: List<LibraryManga>) {
|
private suspend fun updateCovers(mangaToUpdate: List<LibraryManga>) {
|
||||||
var count = 0
|
var progressCount = 0
|
||||||
|
|
||||||
mangaToUpdate.forEach { manga ->
|
mangaToUpdate.forEach { manga ->
|
||||||
notifier.showProgressNotification(manga, count++, mangaToUpdate.size)
|
notifier.showProgressNotification(manga, progressCount++, mangaToUpdate.size)
|
||||||
|
|
||||||
sourceManager.get(manga.source)?.let { source ->
|
sourceManager.get(manga.source)?.let { source ->
|
||||||
try {
|
try {
|
||||||
@ -478,17 +483,18 @@ class LibraryUpdateService(
|
|||||||
* background thread, so it's safe to do heavy operations or network calls here.
|
* background thread, so it's safe to do heavy operations or network calls here.
|
||||||
*/
|
*/
|
||||||
private suspend fun updateTrackings(mangaToUpdate: List<LibraryManga>) {
|
private suspend fun updateTrackings(mangaToUpdate: List<LibraryManga>) {
|
||||||
// Initialize the variables holding the progress of the updates.
|
var progressCount = 0
|
||||||
var count = 0
|
|
||||||
|
|
||||||
val loggedServices = trackManager.services.filter { it.isLogged }
|
val loggedServices = trackManager.services.filter { it.isLogged }
|
||||||
|
|
||||||
mangaToUpdate.forEach { manga ->
|
mangaToUpdate.forEach { manga ->
|
||||||
// Notify manga that will update.
|
// Notify manga that will update.
|
||||||
notifier.showProgressNotification(manga, count++, mangaToUpdate.size)
|
notifier.showProgressNotification(manga, progressCount++, mangaToUpdate.size)
|
||||||
|
|
||||||
// Update the tracking details.
|
// Update the tracking details.
|
||||||
db.getTracks(manga).executeAsBlocking().forEach { track ->
|
db.getTracks(manga).executeAsBlocking()
|
||||||
|
.map { track ->
|
||||||
|
supervisorScope {
|
||||||
|
async {
|
||||||
val service = trackManager.getService(track.sync_id)
|
val service = trackManager.getService(track.sync_id)
|
||||||
if (service != null && service in loggedServices) {
|
if (service != null && service in loggedServices) {
|
||||||
try {
|
try {
|
||||||
@ -501,6 +507,9 @@ class LibraryUpdateService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
.awaitAll()
|
||||||
|
}
|
||||||
|
|
||||||
notifier.cancelProgressNotification()
|
notifier.cancelProgressNotification()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user