From aa7198f082a509b2248a37e0641bcd28822dbe57 Mon Sep 17 00:00:00 2001 From: NarwhalHorns Date: Fri, 20 Feb 2026 16:22:46 +0000 Subject: [PATCH] Optimize tracked library filter (mihonapp-mihon#2977) Co-authored-by: NarwhalHorns Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Co-authored-by: Cuong-Tran <16017808+cuong-tran@users.noreply.github.com> (cherry picked from commit ab214526c6f24466a0432b5c5c7d254a244cd958) --- CHANGELOG.md | 3 +++ .../tachiyomi/ui/library/LibraryScreenModel.kt | 18 +++--------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9139dd71..70e240fe8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co - Minimize memory usage by reducing in-memory cover cache size ([@Lolle2000la](https://github.com/Lolle2000la)) ([#2266](https://github.com/mihonapp/mihon/pull/2266)) - Optimize MAL search queries ([@MajorTanya](https://github.com/MajorTanya)) ([#2832](https://github.com/mihonapp/mihon/pull/2832)) - Reword download reindexing message to avoid confusion ([@MajorTanya](https://github.com/MajorTanya)) ([#2874](https://github.com/mihonapp/mihon/pull/2874)) +- Rework internals for better performance ([@Lolle2000la](https://github.com/Lolle2000la)) ([#2955](https://github.com/mihonapp/mihon/pull/2955)) +- Optimize tracked library filter ([@NarwhalHorns](https://github.com/NarwhalHorns)) ([#2977](https://github.com/mihonapp/mihon/pull/2977)) ### Changed - Update tracker icons ([@AntsyLich](https://github.com/AntsyLich)) ([#2773](https://github.com/mihonapp/mihon/pull/2773)) @@ -34,6 +36,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co - Fix reader not saving read duration when changing chapter ([@AntsyLich](https://github.com/AntsyLich), [@KotlinHero](https://github.com/KotlinHero)) ([#2784](https://github.com/mihonapp/mihon/pull/2784)) - Fix pre-1970 upload date display in chapter list ([@MajorTanya](https://github.com/MajorTanya)) ([#2779](https://github.com/mihonapp/mihon/pull/2779)) - Fix crash when trying to install/update extensions while shizuku is not running ([@NGB-Was-Taken](https://github.com/NGB-Was-Taken)) ([#2837](https://github.com/mihonapp/mihon/pull/2837)) +- Fix Add Repo input not taking up the full dialog width ([@cuong-tran](https://github.com/cuong-tran)) ([#2816](https://github.com/mihonapp/mihon/pull/2816)) ### Other - Enable logcat logging on stable and debug builds without enabling verbose logging ([@NGB-Was-Taken](https://github.com/NGB-Was-Taken)) ([#2836](https://github.com/mihonapp/mihon/pull/2836)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt index 997d996ab..52df18913 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt @@ -450,15 +450,6 @@ class LibraryScreenModel( val filterLewd = preferences.filterLewd // 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: suspend (LibraryItem) -> Boolean = { applyFilter(filterDownloaded) { it.libraryManga.manga.isLocal() || @@ -510,15 +501,12 @@ class LibraryScreenModel( if (isNotLoggedInAnyTrack || trackFiltersIsIgnored) return@tracking true // KMK --> - val mangaTracks = mangaTrackIds[item.id].orEmpty() + val mangaTracks = trackMap[item.id].orEmpty() - // Early return - if (mangaTracks.isEmpty() && includedTracks.isNotEmpty()) return@tracking false + val isExcluded = excludedTracks.isNotEmpty() && mangaTracks.fastAny { it.trackerId in excludedTracks } + val isIncluded = includedTracks.isEmpty() || mangaTracks.fastAny { it.trackerId in includedTracks } // KMK <-- - val isExcluded = excludedTracks.isNotEmpty() && mangaTracks.fastAny { it in excludedTracks } - val isIncluded = includedTracks.isEmpty() || mangaTracks.fastAny { it in includedTracks } - !isExcluded && isIncluded }