fix(chapter): Check if url already managed or not

This commit is contained in:
Ahmad Ansori Palembani 2024-12-15 10:29:01 +07:00
parent 834958a819
commit d99476f9bf
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -77,9 +77,13 @@ suspend fun syncChaptersWithSource(
} }
val toDelete = duplicates + notInSource val toDelete = duplicates + notInSource
val managedUrls = mutableListOf<String>()
for (sourceChapter in sourceChapters) { for (sourceChapter in sourceChapters) {
val chapter = sourceChapter val chapter = sourceChapter
if (chapter.url in managedUrls) continue
if (source is HttpSource) { if (source is HttpSource) {
source.prepareNewChapter(chapter, manga) source.prepareNewChapter(chapter, manga)
} }
@ -108,6 +112,8 @@ suspend fun syncChaptersWithSource(
toChange.add(update) toChange.add(update)
} }
} }
managedUrls.add(chapter.url)
} }
// Return if there's nothing to add, delete or change, avoid unnecessary db transactions. // Return if there's nothing to add, delete or change, avoid unnecessary db transactions.
@ -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 // 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. // Sources MUST return the chapters from most to less recent, which is common.
var itemCount = toAdd.size var itemCount = toAdd.size
var updatedToAdd = toAdd.distinctBy { it.url }.map { toAddItem -> var updatedToAdd = toAdd.map { toAddItem ->
val chapter: Chapter = toAddItem.copy() val chapter: Chapter = toAddItem.copy()
chapter.date_fetch = now + itemCount-- chapter.date_fetch = now + itemCount--