fix(library-merged): Fix download-filter for merged entries (#1232)
This commit is contained in:
parent
95f1e44e34
commit
0db0238d6b
1 changed files with 17 additions and 7 deletions
|
|
@ -423,7 +423,7 @@ class LibraryScreenModel(
|
||||||
// KMK <--
|
// KMK <--
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun List<LibraryItem>.applyFilters(
|
private suspend fun List<LibraryItem>.applyFilters(
|
||||||
trackMap: Map<Long, List<Track>>,
|
trackMap: Map<Long, List<Track>>,
|
||||||
trackingFilter: Map<Long, TriState>,
|
trackingFilter: Map<Long, TriState>,
|
||||||
preferences: ItemPreferences,
|
preferences: ItemPreferences,
|
||||||
|
|
@ -461,11 +461,20 @@ class LibraryScreenModel(
|
||||||
}
|
}
|
||||||
// KMK <--
|
// KMK <--
|
||||||
|
|
||||||
val filterFnDownloaded: (LibraryItem) -> Boolean = {
|
val filterFnDownloaded: suspend (LibraryItem) -> Boolean = {
|
||||||
applyFilter(filterDownloaded) {
|
applyFilter(filterDownloaded) {
|
||||||
it.libraryManga.manga.isLocal() ||
|
it.libraryManga.manga.isLocal() ||
|
||||||
it.downloadCount > 0 ||
|
it.downloadCount > 0 ||
|
||||||
downloadManager.getDownloadCount(it.libraryManga.manga) > 0
|
// KMK -->
|
||||||
|
if (it.libraryManga.manga.source == MERGED_SOURCE_ID) {
|
||||||
|
// FIXME: Calling await in filter could lead to N+1 performance issues.
|
||||||
|
// Should include all the merged references in library query instead.
|
||||||
|
getMergedMangaById.await(it.libraryManga.manga.id)
|
||||||
|
.sumOf { manga -> downloadManager.getDownloadCount(manga) } > 0
|
||||||
|
} else {
|
||||||
|
// KMK <--
|
||||||
|
downloadManager.getDownloadCount(it.libraryManga.manga) > 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -787,13 +796,14 @@ class LibraryScreenModel(
|
||||||
downloadCount = if (preferences.downloadBadge) {
|
downloadCount = if (preferences.downloadBadge) {
|
||||||
// SY -->
|
// SY -->
|
||||||
if (manga.manga.source == MERGED_SOURCE_ID) {
|
if (manga.manga.source == MERGED_SOURCE_ID) {
|
||||||
runBlocking {
|
// FIXME: N+1 performance issues.
|
||||||
getMergedMangaById.await(manga.manga.id)
|
// Should include all the merged references in library query instead.
|
||||||
}.sumOf { downloadManager.getDownloadCount(it) }.toLong()
|
getMergedMangaById.await(manga.manga.id)
|
||||||
|
.sumOf { downloadManager.getDownloadCount(it) }.toLong()
|
||||||
} else {
|
} else {
|
||||||
|
// SY <--
|
||||||
downloadManager.getDownloadCount(manga.manga).toLong()
|
downloadManager.getDownloadCount(manga.manga).toLong()
|
||||||
}
|
}
|
||||||
// SY <--
|
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue