mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
fix: Delete duplicate chapters
This commit is contained in:
parent
8c5b54df5f
commit
ee2acf8b98
1 changed files with 7 additions and 2 deletions
|
@ -107,12 +107,17 @@ suspend fun syncChaptersWithSource(
|
|||
it.chapter_number = ChapterRecognition.parseChapterNumber(it.name, manga.title, it.chapter_number)
|
||||
}
|
||||
|
||||
// Chapters from the db not in the source.
|
||||
val toDelete = dbChapters.filterNot { dbChapter ->
|
||||
val duplicates = dbChapters.groupBy { it.url }
|
||||
.filter { it.value.size > 1 }
|
||||
.flatMap { (_, chapters) ->
|
||||
chapters.drop(1)
|
||||
}
|
||||
val notInSource = dbChapters.filterNot { dbChapter ->
|
||||
sourceChapters.any { sourceChapter ->
|
||||
dbChapter.url == sourceChapter.url
|
||||
}
|
||||
}
|
||||
val toDelete = duplicates + notInSource
|
||||
|
||||
// Return if there's nothing to add, delete or change, avoid unnecessary db transactions.
|
||||
if (toAdd.isEmpty() && toDelete.isEmpty() && toChange.isEmpty()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue