From c1e6f4c26eb75d7ca9a6818bfb538ebee8547a14 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Sat, 23 Oct 2021 19:27:50 +0330 Subject: [PATCH] better cleaning algorithm --- .../kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt index a30a83ef..190d2042 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt @@ -105,14 +105,13 @@ object Chapter { val dbChapterCount = transaction { ChapterTable.select { ChapterTable.manga eq mangaId }.count() } if (dbChapterCount > chapterCount) { // we got some clean up due val dbChapterList = transaction { ChapterTable.select { ChapterTable.manga eq mangaId }.toList() } + val chapterUrls = chapterList.map { it.url }.toSet() - dbChapterList.forEach { - if (it[ChapterTable.sourceOrder] >= chapterList.size || - chapterList[it[ChapterTable.sourceOrder] - 1].url != it[ChapterTable.url] - ) { + dbChapterList.forEach { dbChapter -> + if (!chapterUrls.contains(dbChapter[ChapterTable.url])) { transaction { - PageTable.deleteWhere { PageTable.chapter eq it[ChapterTable.id] } - ChapterTable.deleteWhere { ChapterTable.id eq it[ChapterTable.id] } + PageTable.deleteWhere { PageTable.chapter eq dbChapter[ChapterTable.id] } + ChapterTable.deleteWhere { ChapterTable.id eq dbChapter[ChapterTable.id] } } } }