From d2dd34c2e53818718ec48f0ed9f167e4cacb8db5 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 26 Feb 2023 16:48:04 -0500 Subject: [PATCH] Use queued last chapter read number when performing delayed tracker update Fixes #8876 (cherry picked from commit f7f2072621bbcaf4ddbe07f746a5cf78490c95c9) --- .../track/service/DelayedTrackingUpdateJob.kt | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/track/service/DelayedTrackingUpdateJob.kt b/app/src/main/java/eu/kanade/domain/track/service/DelayedTrackingUpdateJob.kt index 46703440a..521209c48 100644 --- a/app/src/main/java/eu/kanade/domain/track/service/DelayedTrackingUpdateJob.kt +++ b/app/src/main/java/eu/kanade/domain/track/service/DelayedTrackingUpdateJob.kt @@ -31,30 +31,33 @@ class DelayedTrackingUpdateJob(context: Context, workerParams: WorkerParameters) val trackManager = Injekt.get() val delayedTrackingStore = Injekt.get() - withIOContext { - val tracks = delayedTrackingStore.getItems().mapNotNull { - val track = getTracks.awaitOne(it.trackId) - if (track == null) { - delayedTrackingStore.remove(it.trackId) - } - track - } - - tracks.forEach { track -> - try { - val service = trackManager.getService(track.syncId) - if (service != null && service.isLogged) { - service.update(track.toDbTrack(), true) - insertTrack.await(track) + val results = withIOContext { + delayedTrackingStore.getItems() + .mapNotNull { + val track = getTracks.awaitOne(it.trackId) + if (track == null) { + delayedTrackingStore.remove(it.trackId) + } + track?.copy(lastChapterRead = it.lastChapterRead.toDouble()) + } + .mapNotNull { track -> + try { + val service = trackManager.getService(track.syncId) + if (service != null && service.isLogged) { + logcat(LogPriority.DEBUG) { "Updating delayed track item: ${track.id}, last chapter read: ${track.lastChapterRead}" } + service.update(track.toDbTrack(), true) + insertTrack.await(track) + } + delayedTrackingStore.remove(track.id) + null + } catch (e: Exception) { + logcat(LogPriority.ERROR, e) + false } - delayedTrackingStore.remove(track.id) - } catch (e: Exception) { - logcat(LogPriority.ERROR, e) } - } } - return Result.success() + return if (results.isNotEmpty()) Result.failure() else Result.success() } companion object {