Fix reading history being double counted

Restore groups a backup's history entries by chapter before comparing them with the stored row, so a backup carrying one entry per copy of a duplicated chapter no longer adds its reading time more than once or moves the last read backwards. A removed history entry keeps its 0 instead of becoming NULL, a tracker's start date skips removed history, and the reader clears a session's start time before saving it, so overlapping saves can't count it twice.
This commit is contained in:
AntsyLich
2026-09-27 22:55:41 +06:00
parent 8bfa495f34
commit 553762fae8
3 changed files with 27 additions and 26 deletions
@@ -57,9 +57,8 @@ class AddTracks(
if (track.startDate <= 0) {
val firstReadChapterDate = getHistory.await(mangaId)
.sortedBy { it.readAt }
.firstOrNull()
?.readAt
.mapNotNull { it.readAt?.takeIf { readAt -> readAt.time > 0 } }
.minOrNull()
firstReadChapterDate?.let {
val startDate = firstReadChapterDate.time.convertEpochMillisZone(
@@ -629,9 +629,9 @@ class ReaderViewModel(
val chapterId = readerChapter.chapter.id!!
val endTime = Date()
val sessionReadDuration = chapterReadStartTime?.let { endTime.time - it } ?: 0
chapterReadStartTime = null
upsertHistory.await(HistoryUpdate(chapterId, endTime, sessionReadDuration))
chapterReadStartTime = null
}
}