From fc2f5ffdf9c1e8675f9b978031a49fb4ce3af601 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sat, 1 Jun 2024 18:22:25 +0200 Subject: [PATCH] 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" --- .../tachidesk/manga/impl/track/Track.kt | 55 +++++++++++++------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/Track.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/Track.kt index de2e4c9ef..36552a479 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/Track.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/Track.kt @@ -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] + try { + trackChapterForTracker(it, chapterNumber) + } catch (e: Exception) { + KotlinLogging.logger { "${logger.name}::trackChapter(mangaId= $mangaId, chapterNumber= $chapterNumber)" } + .error(e) { "failed due to" } + } + } + } - val log = KotlinLogging.logger { "${logger.name}::trackChapter(mangaId= $mangaId, chapterNumber= $chapterNumber)" } + private suspend fun trackChapterForTracker( + it: ResultRow, + chapterNumber: Double, + ) { + val tracker = TrackerManager.getTracker(it[TrackRecordTable.trackerId]) ?: return + val track = it.toTrack() - if (localLastReadChapter == chapterNumber) { - log.debug { "new chapter is the same as the local last read chapter" } - return@forEach + 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] - val track = it.toTrack() - tracker.refresh(track) + if (localLastReadChapter == chapterNumber) { + log.debug { "new chapter is the same as the local last read chapter" } + return + } + + if (!tracker.isLoggedIn) { upsertTrackRecord(track) + return + } + + tracker.refresh(track) + upsertTrackRecord(track) - val lastChapterRead = track.last_chapter_read + val lastChapterRead = track.last_chapter_read - log.debug { "tracker= $tracker, remoteLastReadChapter= $lastChapterRead" } + log.debug { "remoteLastReadChapter= $lastChapterRead" } - if (tracker.isLoggedIn && chapterNumber > lastChapterRead) { - track.last_chapter_read = chapterNumber.toFloat() - tracker.update(track, true) - upsertTrackRecord(track) - } + if (chapterNumber > lastChapterRead) { + track.last_chapter_read = chapterNumber.toFloat() + tracker.update(track, true) + upsertTrackRecord(track) } }