better cleaning algorithm

This commit is contained in:
Aria Moradi
2021-10-23 19:27:50 +03:30
parent 7c603258fb
commit c1e6f4c26e

View File

@@ -105,14 +105,13 @@ object Chapter {
val dbChapterCount = transaction { ChapterTable.select { ChapterTable.manga eq mangaId }.count() } val dbChapterCount = transaction { ChapterTable.select { ChapterTable.manga eq mangaId }.count() }
if (dbChapterCount > chapterCount) { // we got some clean up due if (dbChapterCount > chapterCount) { // we got some clean up due
val dbChapterList = transaction { ChapterTable.select { ChapterTable.manga eq mangaId }.toList() } val dbChapterList = transaction { ChapterTable.select { ChapterTable.manga eq mangaId }.toList() }
val chapterUrls = chapterList.map { it.url }.toSet()
dbChapterList.forEach { dbChapterList.forEach { dbChapter ->
if (it[ChapterTable.sourceOrder] >= chapterList.size || if (!chapterUrls.contains(dbChapter[ChapterTable.url])) {
chapterList[it[ChapterTable.sourceOrder] - 1].url != it[ChapterTable.url]
) {
transaction { transaction {
PageTable.deleteWhere { PageTable.chapter eq it[ChapterTable.id] } PageTable.deleteWhere { PageTable.chapter eq dbChapter[ChapterTable.id] }
ChapterTable.deleteWhere { ChapterTable.id eq it[ChapterTable.id] } ChapterTable.deleteWhere { ChapterTable.id eq dbChapter[ChapterTable.id] }
} }
} }
} }