feat(library): Optimize trackers filter speed
This commit is contained in:
parent
639459f8af
commit
4e2445d60c
1 changed files with 20 additions and 3 deletions
|
|
@ -451,6 +451,15 @@ class LibraryScreenModel(
|
||||||
val filterLewd = preferences.filterLewd
|
val filterLewd = preferences.filterLewd
|
||||||
// SY <--
|
// SY <--
|
||||||
|
|
||||||
|
// KMK -->
|
||||||
|
// Pre-compute track mappings for better performance
|
||||||
|
val mangaTrackIds = if (!isNotLoggedInAnyTrack && !trackFiltersIsIgnored) {
|
||||||
|
trackMap.mapValues { entry -> entry.value.map { it.trackerId } }
|
||||||
|
} else {
|
||||||
|
emptyMap()
|
||||||
|
}
|
||||||
|
// KMK <--
|
||||||
|
|
||||||
val filterFnDownloaded: (LibraryItem) -> Boolean = {
|
val filterFnDownloaded: (LibraryItem) -> Boolean = {
|
||||||
applyFilter(filterDownloaded) {
|
applyFilter(filterDownloaded) {
|
||||||
it.libraryManga.manga.isLocal() ||
|
it.libraryManga.manga.isLocal() ||
|
||||||
|
|
@ -492,9 +501,12 @@ class LibraryScreenModel(
|
||||||
val filterFnTracking: (LibraryItem) -> Boolean = tracking@{ item ->
|
val filterFnTracking: (LibraryItem) -> Boolean = tracking@{ item ->
|
||||||
if (isNotLoggedInAnyTrack || trackFiltersIsIgnored) return@tracking true
|
if (isNotLoggedInAnyTrack || trackFiltersIsIgnored) return@tracking true
|
||||||
|
|
||||||
val mangaTracks = trackMap
|
// KMK -->
|
||||||
.mapValues { entry -> entry.value.map { it.trackerId } }[item.id]
|
val mangaTracks = mangaTrackIds[item.id].orEmpty()
|
||||||
.orEmpty()
|
|
||||||
|
// Early return
|
||||||
|
if (mangaTracks.isEmpty() && includedTracks.isNotEmpty()) return@tracking false
|
||||||
|
// KMK <--
|
||||||
|
|
||||||
val isExcluded = excludedTracks.isNotEmpty() && mangaTracks.fastAny { it in excludedTracks }
|
val isExcluded = excludedTracks.isNotEmpty() && mangaTracks.fastAny { it in excludedTracks }
|
||||||
val isIncluded = includedTracks.isEmpty() || mangaTracks.fastAny { it in includedTracks }
|
val isIncluded = includedTracks.isEmpty() || mangaTracks.fastAny { it in includedTracks }
|
||||||
|
|
@ -508,6 +520,11 @@ class LibraryScreenModel(
|
||||||
|
|
||||||
val mangaCategories = item.libraryManga.categories.filterNot { it == 0L }.toSet()
|
val mangaCategories = item.libraryManga.categories.filterNot { it == 0L }.toSet()
|
||||||
|
|
||||||
|
// Early return
|
||||||
|
if (mangaCategories.isEmpty()) {
|
||||||
|
return@categories includedCategories.isEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
val isExcluded = excludedCategories.any { it in mangaCategories }
|
val isExcluded = excludedCategories.any { it in mangaCategories }
|
||||||
val isIncluded = includedCategories.isEmpty() || includedCategories.all { it in mangaCategories }
|
val isIncluded = includedCategories.isEmpty() || includedCategories.all { it in mangaCategories }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue