Skip to content
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

Merged
merged 3 commits into from
Feb 19, 2022
Merged

auto-remove duplicate chapters #294

merged 3 commits into from
Feb 19, 2022

Conversation

AriaMoradi
Copy link
Member

No description provided.

@AriaMoradi AriaMoradi requested a review from Syer10 February 19, 2022 00:34
@Syer10
Copy link
Collaborator

Syer10 commented Feb 19, 2022

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

@AriaMoradi
Copy link
Member Author

your's is not deterministic, mine always makes sure there's a non-duplicate with bigger index exists to check with the next?

Copy link
Collaborator

@Syer10 Syer10 left a 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

@AriaMoradi AriaMoradi merged commit c289786 into master Feb 19, 2022
@AriaMoradi AriaMoradi deleted the chapter-duplicate branch February 19, 2022 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants