fix(favorites): save server favourites through to the cache (DR-115)

The hybrid favourites read went straight to the online repository on a
cache miss and dropped the result on the floor. Every other read path
persists what it fetches, so this one made the favourites page re-query
the server on every visit — and left the offline mirror (DR-114) empty on
a fresh install, since this is the path that fills it.

It now goes through get_favorites_server_only, which saves through on the
way back.

The command had a matching hole: with nothing cached it returned the empty
result, painting "Nothing favourited yet" at a viewer whose favourites
were simply marked on another client. It now asks the repository for a
real answer instead of an empty state it would correct a round trip later.

TRACES: UR-067 | DR-115
This commit is contained in:
2026-08-04 20:20:36 +02:00
parent 30dc3ba7f6
commit f7bcfe521d
4 changed files with 33 additions and 9 deletions
+7 -8
View File
@@ -853,13 +853,7 @@ impl MediaRepository for HybridRepository {
scope: SearchScope,
options: Option<GetItemsOptions>,
) -> Result<SearchResult, RepoError> {
let offline = Arc::clone(&self.offline);
let online = Arc::clone(&self.online);
let opts_clone = options.clone();
let cache_result = self
.cache_with_timeout(async move { offline.get_favorites(scope, opts_clone).await })
.await;
let cache_result = self.get_favorites_cache_only(scope, options.clone()).await;
// Downloads-only gate: with "Show all server media" off, an empty local
// result means "nothing favourited is on this device" and is
@@ -877,7 +871,12 @@ impl MediaRepository for HybridRepository {
}
}
match online.get_favorites(scope, options).await {
// Cache miss — answer from the server, *saving through* on the way back.
// Every other read path persists what it fetches; skipping it here would
// mean the favourites page re-queries the server on every visit and the
// offline mirror (DR-114) never learns about favourites marked
// elsewhere, since this path is what fills it on a fresh install.
match self.get_favorites_server_only(scope, options).await {
Ok(data) => Ok(data),
Err(e) => cache_result.or(Err(e)),
}