From 36cb899b91b3bfcfb94a8baf85e9db7a6e752d6c Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sat, 15 Feb 2025 05:05:04 +0100 Subject: [PATCH] Prevent chapter lastReadPage coerceIn error (#1272) coerceIn throws an error in case the max value is less than the min value ("Cannot coerce value to an empty range: maximum is less than minimum ") Regression from c8bd39b4bfee44005614df5b647e803279e5218e --- .../suwayomi/tachidesk/graphql/mutations/ChapterMutation.kt | 2 +- .../suwayomi/tachidesk/manga/impl/chapter/ChapterForDownload.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/ChapterMutation.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/ChapterMutation.kt index b40b132b..5c809293 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/ChapterMutation.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/ChapterMutation.kt @@ -85,7 +85,7 @@ class ChapterMutation { this[ChapterTable.isBookmarked] = it } patch.lastPageRead?.also { - this[ChapterTable.lastPageRead] = it.coerceIn(0, chapterIdToPageCount[chapterId]) + this[ChapterTable.lastPageRead] = it.coerceAtMost(chapterIdToPageCount[chapterId] ?: 0).coerceAtLeast(0) this[ChapterTable.lastReadAt] = now } } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/chapter/ChapterForDownload.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/chapter/ChapterForDownload.kt index 36e7c41f..e6616466 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/chapter/ChapterForDownload.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/chapter/ChapterForDownload.kt @@ -159,7 +159,7 @@ private class ChapterForDownload( ChapterTable.update({ ChapterTable.id eq chapterId }) { val pageCount = pageList.size it[ChapterTable.pageCount] = pageCount - it[ChapterTable.lastPageRead] = chapterEntry[ChapterTable.lastPageRead].coerceIn(0, pageCount - 1) + it[ChapterTable.lastPageRead] = chapterEntry[ChapterTable.lastPageRead].coerceAtMost(pageCount - 1).coerceAtLeast(0) } } }