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 <--
|
||||
}
|
||||
|
||||
private fun List<LibraryItem>.applyFilters(
|
||||
private suspend fun List<LibraryItem>.applyFilters(
|
||||
trackMap: Map<Long, List<Track>>,
|
||||
trackingFilter: Map<Long, TriState>,
|
||||
preferences: ItemPreferences,
|
||||
|
|
@ -461,13 +461,22 @@ class LibraryScreenModel(
|
|||
}
|
||||
// KMK <--
|
||||
|
||||
val filterFnDownloaded: (LibraryItem) -> Boolean = {
|
||||
val filterFnDownloaded: suspend (LibraryItem) -> Boolean = {
|
||||
applyFilter(filterDownloaded) {
|
||||
it.libraryManga.manga.isLocal() ||
|
||||
it.downloadCount > 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val filterFnUnread: (LibraryItem) -> Boolean = {
|
||||
applyFilter(filterUnread) { it.libraryManga.unreadCount > 0 }
|
||||
|
|
@ -787,13 +796,14 @@ class LibraryScreenModel(
|
|||
downloadCount = if (preferences.downloadBadge) {
|
||||
// SY -->
|
||||
if (manga.manga.source == MERGED_SOURCE_ID) {
|
||||
runBlocking {
|
||||
// FIXME: N+1 performance issues.
|
||||
// Should include all the merged references in library query instead.
|
||||
getMergedMangaById.await(manga.manga.id)
|
||||
}.sumOf { downloadManager.getDownloadCount(it) }.toLong()
|
||||
.sumOf { downloadManager.getDownloadCount(it) }.toLong()
|
||||
} else {
|
||||
// SY <--
|
||||
downloadManager.getDownloadCount(manga.manga).toLong()
|
||||
}
|
||||
// SY <--
|
||||
} else {
|
||||
0
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue