From 043c7bd87421bdcd4c81c9ec6a65e557aa4427ab Mon Sep 17 00:00:00 2001 From: zarzet <42882290+zarzet@users.noreply.github.com> Date: Sun, 20 Sep 2026 17:21:01 +0700 Subject: [PATCH] perf(search): release derived caches when track results change Clear cached buckets, sorted results and history lookups when the source track list changes. This releases the previous search even when empty, loading or error branches skip building results. --- lib/screens/home_tab.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/screens/home_tab.dart b/lib/screens/home_tab.dart index e50fe60b..e34a8ecf 100644 --- a/lib/screens/home_tab.dart +++ b/lib/screens/home_tab.dart @@ -361,6 +361,14 @@ class _HomeTabState extends ConsumerState } void _onTrackStateChanged(TrackState? previous, TrackState next) { + if (!identical(previous?.tracks, next.tracks)) { + // Home stays alive across tabs. Empty/loading/error branches can skip + // result building, so release the previous search's derived lists here. + _searchBucketsSourceTracks = null; + _searchBucketsCache = null; + _invalidateSearchSortCaches(); + _historySnapshot.update(const []); + } if (previous != null && !next.hasContent && !next.hasSearchText &&