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.
This commit is contained in:
zarzet committed 2026-09-20 17:21:01 +07:00
1 parent d91bfae155
commit 043c7bd874
1 file changed
+8
+8
View File
@@ -361,6 +361,14 @@ class _HomeTabState extends ConsumerState<HomeTab>
}
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 &&