perf(cache): enforce cover byte budget during foreground use

This commit is contained in:
zarzet
2026-09-06 02:33:43 +07:00
parent dae509078e
commit 3368cf8c5d
5 changed files with 214 additions and 46 deletions
+3
View File
@@ -251,6 +251,7 @@ class _EagerInitializationState extends ConsumerState<_EagerInitialization>
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
CoverCacheManager.stopMaintenance();
_localLibraryEnabledSub?.close();
_downloadHistoryWarmupTimer?.cancel();
_localLibraryWarmupTimer?.cancel();
@@ -260,6 +261,7 @@ class _EagerInitializationState extends ConsumerState<_EagerInitialization>
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
CoverCacheManager.scheduleMaintenance();
_maybeAutoScanLocalLibrary();
if (ref.exists(localLibraryProvider)) {
unawaited(
@@ -274,6 +276,7 @@ class _EagerInitializationState extends ConsumerState<_EagerInitialization>
.resumePendingDownloadsOnForeground();
}
} else if (state == AppLifecycleState.paused) {
CoverCacheManager.stopMaintenance();
// Last reliable moment before the OS may kill the process: make sure
// any debounced download-queue persistence reaches disk.
if (ref.exists(downloadQueueProvider)) {