mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-06-30 09:24:34 -05:00
Fix/chapter list update preserving download state (#2050)
* Fix preserving chapter download state of deleted chapters * Fix preserving chapter download state of updated chapters
This commit is contained in:
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|||||||
- (**WebUI**) Handle serving non-default webui with "bundled"
|
- (**WebUI**) Handle serving non-default webui with "bundled"
|
||||||
- (**WebUI**) Wait until WebUI is ready to open in browser
|
- (**WebUI**) Wait until WebUI is ready to open in browser
|
||||||
- (**Downloads**) Truncate filenames by byte length to prevent "File name too long" IO errors
|
- (**Downloads**) Truncate filenames by byte length to prevent "File name too long" IO errors
|
||||||
|
- (**Downloads**) Fix preserving chapter download states during an update
|
||||||
- (**Extension**) Do not indicate an update is available when the extension is not installed
|
- (**Extension**) Do not indicate an update is available when the extension is not installed
|
||||||
- (**Chapter**) Fix losing chapter data on failed chapter list update
|
- (**Chapter**) Fix losing chapter data on failed chapter list update
|
||||||
- (**Chapter**) Fix database error when fetching chapter updates
|
- (**Chapter**) Fix database error when fetching chapter updates
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ object Chapter {
|
|||||||
val deletedChapterNumbers = TreeSet<Float>()
|
val deletedChapterNumbers = TreeSet<Float>()
|
||||||
val deletedReadChapterNumbers = TreeSet<Float>()
|
val deletedReadChapterNumbers = TreeSet<Float>()
|
||||||
val deletedBookmarkedChapterNumbers = TreeSet<Float>()
|
val deletedBookmarkedChapterNumbers = TreeSet<Float>()
|
||||||
val deletedDownloadedChapterNumberInfoMap = mutableMapOf<Float, MutableMap<String?, Int>>()
|
val deletedDownloadedChapterNumberToChapter = mutableMapOf<Float, ChapterDataClass>()
|
||||||
val deletedChapterNumberDateFetchMap = mutableMapOf<Float, Long>()
|
val deletedChapterNumberDateFetchMap = mutableMapOf<Float, Long>()
|
||||||
|
|
||||||
// clear any orphaned/duplicate chapters that are in the db but not in `chapterList`
|
// clear any orphaned/duplicate chapters that are in the db but not in `chapterList`
|
||||||
@@ -247,13 +247,7 @@ object Chapter {
|
|||||||
if (!chapterUrls.contains(dbChapter.url)) {
|
if (!chapterUrls.contains(dbChapter.url)) {
|
||||||
if (dbChapter.read) deletedReadChapterNumbers.add(dbChapter.chapterNumber)
|
if (dbChapter.read) deletedReadChapterNumbers.add(dbChapter.chapterNumber)
|
||||||
if (dbChapter.bookmarked) deletedBookmarkedChapterNumbers.add(dbChapter.chapterNumber)
|
if (dbChapter.bookmarked) deletedBookmarkedChapterNumbers.add(dbChapter.chapterNumber)
|
||||||
if (dbChapter.downloaded) {
|
if (dbChapter.downloaded) deletedDownloadedChapterNumberToChapter[dbChapter.chapterNumber] = dbChapter
|
||||||
val pageCountByScanlator =
|
|
||||||
deletedDownloadedChapterNumberInfoMap.getOrPut(
|
|
||||||
dbChapter.chapterNumber,
|
|
||||||
) { mutableMapOf() }
|
|
||||||
pageCountByScanlator[dbChapter.scanlator] = dbChapter.pageCount
|
|
||||||
}
|
|
||||||
deletedChapterNumbers.add(dbChapter.chapterNumber)
|
deletedChapterNumbers.add(dbChapter.chapterNumber)
|
||||||
deletedChapterNumberDateFetchMap[dbChapter.chapterNumber] = dbChapter.fetchedAt
|
deletedChapterNumberDateFetchMap[dbChapter.chapterNumber] = dbChapter.fetchedAt
|
||||||
dbChapter.id
|
dbChapter.id
|
||||||
@@ -292,18 +286,24 @@ object Chapter {
|
|||||||
this[ChapterTable.isRead] = chapter.chapterNumber in deletedReadChapterNumbers
|
this[ChapterTable.isRead] = chapter.chapterNumber in deletedReadChapterNumbers
|
||||||
this[ChapterTable.isBookmarked] = chapter.chapterNumber in deletedBookmarkedChapterNumbers
|
this[ChapterTable.isBookmarked] = chapter.chapterNumber in deletedBookmarkedChapterNumbers
|
||||||
|
|
||||||
// only preserve download status for chapters of the same scanlator, otherwise,
|
|
||||||
// the downloaded files won't be found anyway
|
|
||||||
val downloadedChapterInfo = deletedDownloadedChapterNumberInfoMap[chapter.chapterNumber]
|
|
||||||
val pageCount = downloadedChapterInfo?.get(chapter.scanlator)
|
|
||||||
if (pageCount != null) {
|
|
||||||
this[ChapterTable.isDownloaded] = true
|
|
||||||
this[ChapterTable.pageCount] = pageCount
|
|
||||||
}
|
|
||||||
// Try to use the fetch date of the original entry to not pollute 'Updates' tab
|
// Try to use the fetch date of the original entry to not pollute 'Updates' tab
|
||||||
deletedChapterNumberDateFetchMap[chapter.chapterNumber]?.let {
|
deletedChapterNumberDateFetchMap[chapter.chapterNumber]?.let {
|
||||||
this[ChapterTable.fetchedAt] = it
|
this[ChapterTable.fetchedAt] = it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val deletedChapter = deletedDownloadedChapterNumberToChapter[chapter.chapterNumber]!!
|
||||||
|
|
||||||
|
val hasDownloadedPages = deletedChapter.pageCount > 0
|
||||||
|
val isSameName = deletedChapter.name == chapter.name
|
||||||
|
val isSameScanlator = deletedChapter.scanlator == chapter.scanlator
|
||||||
|
|
||||||
|
// Only preserve download status for chapters with the same name and of the same scanlator; otherwise,
|
||||||
|
// the downloaded files won't be found anyway
|
||||||
|
val isDownloadPreservable = hasDownloadedPages && isSameName && isSameScanlator
|
||||||
|
if (isDownloadPreservable) {
|
||||||
|
this[ChapterTable.isDownloaded] = true
|
||||||
|
this[ChapterTable.pageCount] = deletedChapter.pageCount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.forEach { insertedChapters.add(ChapterTable.toDataClass(it)) }
|
}.forEach { insertedChapters.add(ChapterTable.toDataClass(it)) }
|
||||||
}
|
}
|
||||||
@@ -313,12 +313,30 @@ object Chapter {
|
|||||||
.apply {
|
.apply {
|
||||||
chaptersToUpdate.forEach {
|
chaptersToUpdate.forEach {
|
||||||
addBatch(EntityID(it.id, ChapterTable))
|
addBatch(EntityID(it.id, ChapterTable))
|
||||||
|
|
||||||
|
val currentChapter = chaptersInDb.find { dbChapter -> dbChapter.id == it.id }!!
|
||||||
|
|
||||||
this[ChapterTable.name] = it.name
|
this[ChapterTable.name] = it.name
|
||||||
this[ChapterTable.date_upload] = it.uploadDate
|
this[ChapterTable.date_upload] = it.uploadDate
|
||||||
this[ChapterTable.chapter_number] = it.chapterNumber
|
this[ChapterTable.chapter_number] = it.chapterNumber
|
||||||
this[ChapterTable.scanlator] = it.scanlator
|
this[ChapterTable.scanlator] = it.scanlator
|
||||||
this[ChapterTable.sourceOrder] = it.index
|
this[ChapterTable.sourceOrder] = it.index
|
||||||
this[ChapterTable.realUrl] = it.realUrl
|
this[ChapterTable.realUrl] = it.realUrl
|
||||||
|
this[ChapterTable.isDownloaded] = currentChapter.downloaded
|
||||||
|
this[ChapterTable.pageCount] = currentChapter.pageCount
|
||||||
|
|
||||||
|
if (!currentChapter.downloaded) {
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSameScanlator = currentChapter.scanlator == it.scanlator
|
||||||
|
val isSameName = currentChapter.name == it.name
|
||||||
|
|
||||||
|
val isDownloadPreservable = isSameName && isSameScanlator
|
||||||
|
if (!isDownloadPreservable) {
|
||||||
|
this[ChapterTable.isDownloaded] = false
|
||||||
|
this[ChapterTable.pageCount] = -1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.toExecutable()
|
}.toExecutable()
|
||||||
.execute(this@transaction)
|
.execute(this@transaction)
|
||||||
|
|||||||
Reference in New Issue
Block a user