fix(library): De-duplicate entries mistakenly created in DB

This commit is contained in:
Cuong-Tran 2025-08-15 14:58:34 +07:00
parent 379d36e586
commit 3485297434

View file

@ -552,7 +552,13 @@ class LibraryScreenModel(
// KMK --> // KMK -->
.filterNot { !showHiddenCategories && it.hidden } .filterNot { !showHiddenCategories && it.hidden }
// KMK <-- // KMK <--
.associateWith { groupCache[it.id]?.toList().orEmpty() } .associateWith {
groupCache[it.id]?.toList()
// KMK -->
?.distinct()
// KMK <--
.orEmpty()
}
} }
// KMK --> // KMK -->
LibraryGroup.UNGROUPED -> { LibraryGroup.UNGROUPED -> {
@ -1019,13 +1025,15 @@ class LibraryScreenModel(
fun removeMangas(mangas: List<Manga>, deleteFromLibrary: Boolean, deleteChapters: Boolean) { fun removeMangas(mangas: List<Manga>, deleteFromLibrary: Boolean, deleteChapters: Boolean) {
screenModelScope.launchNonCancellable { screenModelScope.launchNonCancellable {
if (deleteFromLibrary) { if (deleteFromLibrary) {
val toDelete = mangas.map { val toDelete = mangas
it.removeCovers(coverCache) .distinctBy { it.id }
MangaUpdate( .map {
favorite = false, it.removeCovers(coverCache)
id = it.id, MangaUpdate(
) favorite = false,
} id = it.id,
)
}
updateManga.awaitAll(toDelete) updateManga.awaitAll(toDelete)
} }
@ -1424,6 +1432,9 @@ class LibraryScreenModel(
// KMK <-- // KMK <--
) )
} }
// KMK -->
.mapValues { (_, values) -> values.distinct() }
// KMK <--
} }
LibraryGroup.BY_SOURCE -> { LibraryGroup.BY_SOURCE -> {
// KMK --> // KMK -->
@ -1484,7 +1495,7 @@ class LibraryScreenModel(
) )
} }
// KMK --> // KMK -->
.mapValues { (_, libraryItem) -> libraryItem.fastMap { it.id } } .mapValues { (_, libraryItem) -> libraryItem.fastMap { it.id }.distinct() }
// KMK <-- // KMK <--
} }
else -> emptyMap() else -> emptyMap()