From ae9306988ef8e78ba04f79e8a5e7aecfee6837b5 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Fri, 28 Aug 2026 19:54:47 -0600 Subject: [PATCH] fix(offline-cache): touch last_accessed_at when a cached track plays OfflineCacheDb::touch had no caller, so LRU eviction ordered by the download date and evicted the most-played tracks first. Touch in resolve_offline_bytes, the one resolver every offline play goes through. cc --- crates/qbz-core/src/offline_resolve.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/qbz-core/src/offline_resolve.rs b/crates/qbz-core/src/offline_resolve.rs index 927073cce..c28ca3ab1 100644 --- a/crates/qbz-core/src/offline_resolve.rs +++ b/crates/qbz-core/src/offline_resolve.rs @@ -33,7 +33,17 @@ pub async fn resolve_offline_bytes( ) -> Option> { let row = { let guard = offline.db.lock().await; - guard.as_ref()?.get_cmaf_bundle(track_id).ok().flatten()? + let db = guard.as_ref()?; + let row = db.get_cmaf_bundle(track_id).ok().flatten()?; + // A play IS an access. LRU eviction (`maintenance::check_cache_limit`) + // orders by `last_accessed_at`, which until now only the download + // wrote — so the cache evicted the tracks the user played most, + // oldest download first. This is the one place every offline play + // funnels through (both frontends and qbzd resolve here). + if let Err(e) = db.touch(track_id) { + log::debug!("[OfflineResolve] touch({track_id}) failed: {e}"); + } + row }; match row.cache_format {