mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Improve DelayedTrackerStore (#8109)
* Improve DelayedTrackerStore * Review changes
This commit is contained in:
parent
8b9a06e298
commit
ad84a8c3e9
3 changed files with 10 additions and 10 deletions
|
@ -25,9 +25,9 @@ class DelayedTrackingStore(context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
fun remove(track: Track) {
|
||||
preferences.edit {
|
||||
clear()
|
||||
remove(track.id.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,8 @@ import eu.kanade.domain.track.interactor.GetTracks
|
|||
import eu.kanade.domain.track.interactor.InsertTrack
|
||||
import eu.kanade.domain.track.model.toDbTrack
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import logcat.LogPriority
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
@ -33,9 +32,9 @@ class DelayedTrackingUpdateJob(context: Context, workerParams: WorkerParameters)
|
|||
val trackManager = Injekt.get<TrackManager>()
|
||||
val delayedTrackingStore = Injekt.get<DelayedTrackingStore>()
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
withIOContext {
|
||||
val tracks = delayedTrackingStore.getItems().mapNotNull {
|
||||
val manga = getManga.await(it.mangaId) ?: return@withContext
|
||||
val manga = getManga.await(it.mangaId) ?: return@withIOContext
|
||||
getTracks.await(manga.id)
|
||||
.find { track -> track.id == it.trackId }
|
||||
?.copy(lastChapterRead = it.lastChapterRead.toDouble())
|
||||
|
@ -48,12 +47,11 @@ class DelayedTrackingUpdateJob(context: Context, workerParams: WorkerParameters)
|
|||
service.update(track.toDbTrack(), true)
|
||||
insertTrack.await(track)
|
||||
}
|
||||
delayedTrackingStore.remove(track)
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
}
|
||||
}
|
||||
|
||||
delayedTrackingStore.clear()
|
||||
}
|
||||
|
||||
return Result.success()
|
||||
|
|
|
@ -843,12 +843,14 @@ class ReaderPresenter(
|
|||
// for a while. The view can still be garbage collected.
|
||||
async {
|
||||
runCatching {
|
||||
if (context.isOnline()) {
|
||||
try {
|
||||
if (!context.isOnline()) error("Couldn't update tracker as device is offline")
|
||||
service.update(updatedTrack.toDbTrack(), true)
|
||||
insertTrack.await(updatedTrack)
|
||||
} else {
|
||||
} catch (e: Exception) {
|
||||
delayedTrackingStore.addItem(updatedTrack)
|
||||
DelayedTrackingUpdateJob.setupTask(context)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue