Skip to content

Commit

Permalink
fix(chapter): Check if url already managed or not
Browse files Browse the repository at this point in the history
  • Loading branch information
null2264 committed Dec 15, 2024
1 parent 834958a commit d99476f
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ suspend fun syncChaptersWithSource(
}
val toDelete = duplicates + notInSource

val managedUrls = mutableListOf<String>()

for (sourceChapter in sourceChapters) {
val chapter = sourceChapter

if (chapter.url in managedUrls) continue

if (source is HttpSource) {
source.prepareNewChapter(chapter, manga)
}
Expand Down Expand Up @@ -108,6 +112,8 @@ suspend fun syncChaptersWithSource(
toChange.add(update)
}
}

managedUrls.add(chapter.url)
}

// Return if there's nothing to add, delete or change, avoid unnecessary db transactions.
Expand Down Expand Up @@ -137,7 +143,7 @@ suspend fun syncChaptersWithSource(
// Date fetch is set in such a way that the upper ones will have bigger value than the lower ones
// Sources MUST return the chapters from most to less recent, which is common.
var itemCount = toAdd.size
var updatedToAdd = toAdd.distinctBy { it.url }.map { toAddItem ->
var updatedToAdd = toAdd.map { toAddItem ->
val chapter: Chapter = toAddItem.copy()

chapter.date_fetch = now + itemCount--
Expand Down

0 comments on commit d99476f

Please sign in to comment.