Skip to content

Commit

Permalink
Fix: duplicate chapters on backup restoring (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
cuong-tran authored Dec 31, 2024
1 parent 23d53a4 commit 8c4b43c
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class MangaRestorer(
when {
dbChapter == null -> chapter // New chapter
chapter.forComparison() == dbChapter.forComparison() -> null // Same state; skip
else -> updateChapterBasedOnSyncState(chapter, dbChapter)
else -> updateChapterBasedOnSyncState(chapter, dbChapter) // Update existed chapter
}
}
.partition { it.id > 0 }
Expand Down Expand Up @@ -217,11 +217,24 @@ class MangaRestorer(
else -> it
}
}
// KMK -->
.copy(id = dbChapter.id)
// KMK <--
}
}

private fun Chapter.forComparison() =
this.copy(id = 0L, mangaId = 0L, dateFetch = 0L, dateUpload = 0L, lastModifiedAt = 0L, version = 0L)
this.copy(
id = 0L,
mangaId = 0L,
dateFetch = 0L,
// KMK -->
// dateUpload = 0L, some time source loses dateUpload so we overwrite with backup
sourceOrder = 0L, // ignore sourceOrder since it will be updated on refresh
// KMK <--
lastModifiedAt = 0L,
version = 0L,
)

private suspend fun insertNewChapters(chapters: List<Chapter>) {
handler.await(true) {
Expand Down Expand Up @@ -258,7 +271,9 @@ class MangaRestorer(
chapterNumber = null,
sourceOrder = if (isSync) chapter.sourceOrder else null,
dateFetch = null,
dateUpload = null,
// KMK -->
dateUpload = chapter.dateUpload,
// KMK <--
chapterId = chapter.id,
version = chapter.version,
isSyncing = 1,
Expand Down

0 comments on commit 8c4b43c

Please sign in to comment.