Fix/failing track progress update for logged out trackers (#953)
* Refresh track record only when logged in In case one tracker was logged out, the refresh failed with an unauthenticated error and caused the other trackers to not get updated * Prevent chapter track update from failing due to failure of other tracker * Change level of log to "info"
This commit is contained in:
@@ -281,7 +281,7 @@ object Track {
|
||||
val chapter = queryMaxReadChapter(mangaId)
|
||||
val chapterNumber = chapter?.get(ChapterTable.chapter_number)
|
||||
|
||||
logger.debug {
|
||||
logger.info {
|
||||
"trackChapter(mangaId= $mangaId): maxReadChapter= #$chapterNumber ${chapter?.get(ChapterTable.name)}"
|
||||
}
|
||||
|
||||
@@ -310,30 +310,51 @@ object Track {
|
||||
}
|
||||
|
||||
records.forEach {
|
||||
val tracker = TrackerManager.getTracker(it[TrackRecordTable.trackerId]) ?: return@forEach
|
||||
|
||||
val localLastReadChapter = it[TrackRecordTable.lastChapterRead]
|
||||
|
||||
val log = KotlinLogging.logger { "${logger.name}::trackChapter(mangaId= $mangaId, chapterNumber= $chapterNumber)" }
|
||||
|
||||
if (localLastReadChapter == chapterNumber) {
|
||||
log.debug { "new chapter is the same as the local last read chapter" }
|
||||
return@forEach
|
||||
try {
|
||||
trackChapterForTracker(it, chapterNumber)
|
||||
} catch (e: Exception) {
|
||||
KotlinLogging.logger { "${logger.name}::trackChapter(mangaId= $mangaId, chapterNumber= $chapterNumber)" }
|
||||
.error(e) { "failed due to" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val track = it.toTrack()
|
||||
tracker.refresh(track)
|
||||
private suspend fun trackChapterForTracker(
|
||||
it: ResultRow,
|
||||
chapterNumber: Double,
|
||||
) {
|
||||
val tracker = TrackerManager.getTracker(it[TrackRecordTable.trackerId]) ?: return
|
||||
val track = it.toTrack()
|
||||
|
||||
val log =
|
||||
KotlinLogging.logger {
|
||||
"${logger.name}::trackChapterForTracker(chapterNumber= $chapterNumber, tracker= ${tracker.id}, recordId= ${track.id})"
|
||||
}
|
||||
log.debug { "called for $tracker, ${track.title} (recordId= ${track.id}, mangaId= ${track.manga_id})" }
|
||||
|
||||
val localLastReadChapter = it[TrackRecordTable.lastChapterRead]
|
||||
|
||||
if (localLastReadChapter == chapterNumber) {
|
||||
log.debug { "new chapter is the same as the local last read chapter" }
|
||||
return
|
||||
}
|
||||
|
||||
if (!tracker.isLoggedIn) {
|
||||
upsertTrackRecord(track)
|
||||
return
|
||||
}
|
||||
|
||||
val lastChapterRead = track.last_chapter_read
|
||||
tracker.refresh(track)
|
||||
upsertTrackRecord(track)
|
||||
|
||||
log.debug { "tracker= $tracker, remoteLastReadChapter= $lastChapterRead" }
|
||||
val lastChapterRead = track.last_chapter_read
|
||||
|
||||
if (tracker.isLoggedIn && chapterNumber > lastChapterRead) {
|
||||
track.last_chapter_read = chapterNumber.toFloat()
|
||||
tracker.update(track, true)
|
||||
upsertTrackRecord(track)
|
||||
}
|
||||
log.debug { "remoteLastReadChapter= $lastChapterRead" }
|
||||
|
||||
if (chapterNumber > lastChapterRead) {
|
||||
track.last_chapter_read = chapterNumber.toFloat()
|
||||
tracker.update(track, true)
|
||||
upsertTrackRecord(track)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user