Skip to content

Commit

Permalink
Fix/failing track progress update for logged out trackers (#953)
Browse files Browse the repository at this point in the history
* 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"
  • Loading branch information
schroda authored Jun 1, 2024
1 parent 6dd9ed7 commit fc2f5ff
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions server/src/main/kotlin/suwayomi/tachidesk/manga/impl/track/Track.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
}

Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit fc2f5ff

Please sign in to comment.