-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
auto-remove duplicate chapters #294
Conversation
I took a gander at this, I think it looks much cleaner 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 { dbChapter ->
if (
!chapterUrls.contains(dbChapter[ChapterTable.url]) || // is orphaned
dbChapterList.count { it[ChapterTable.url] == dbChapter[ChapterTable.url] } > 1 // is duplicate
) {
transaction {
PageTable.deleteWhere { PageTable.chapter eq dbChapter[ChapterTable.id] }
ChapterTable.deleteWhere { ChapterTable.id eq dbChapter[ChapterTable.id] }
}
}
}
} Though it may have issues where yours doesnt, not too sure if they are equal |
your's is not deterministic, mine always makes sure there's a non-duplicate with bigger index exists to check with the next? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont like non-descriptive variables like i, changed to index. Also cleaned up the code
server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt
Outdated
Show resolved
Hide resolved
server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt
Outdated
Show resolved
Hide resolved
server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Chapter.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Mitchell Syer <[email protected]>
No description provided.