fix(home): plumb album awards through backend + invalidate stale home cache

The ribbon feature relied on album.awards arriving on the frontend, but
the DiscoverAlbum Rust struct in both qbz-models and src-tauri/api was
missing the 'awards' field, so serde silently dropped it during
deserialization of /discover/index. Result: frontend always saw an
empty awards array and pickAlbumRibbon returned undefined.

Also bumps the home sessionStorage cache to schemaVersion 2 so pre-fix
caches (which persisted AlbumCardData without ribbon) are discarded on
next launch instead of rehydrating with missing fields.

cc
This commit is contained in:
vicrodh committed 2026-04-14 10:32:28 -06:00
1 parent 89c9ee1028
commit b738c27507
3 files changed
+25 -2

No files matched your search

+4
View File
@@ -631,6 +631,10 @@ pub struct DiscoverAlbum {
pub genre: Option<Genre>,
pub dates: Option<DiscoverAlbumDates>,
pub audio_info: Option<DiscoverAudioInfo>,
/// Editorial awards attached to the album. Id 88 = Qobuzissime,
/// id 151 = Qobuz Album of the Week (locale-stable).
#[serde(default)]
pub awards: Option<Vec<PageArtistAward>>,
}
/// Album image from discover endpoint
+4
View File
@@ -811,6 +811,10 @@ pub struct DiscoverAlbum {
pub genre: Option<Genre>,
pub dates: Option<DiscoverAlbumDates>,
pub audio_info: Option<DiscoverAudioInfo>,
/// Editorial awards attached to the album. Id 88 = Qobuzissime,
/// id 151 = Qobuz Album of the Week (locale-stable).
#[serde(default)]
pub awards: Option<Vec<PageArtistAward>>,
}
/// Album image from discover endpoint
+17 -2
View File
@@ -55,6 +55,7 @@ export interface HomeCacheData {
timestamp: number;
genreIds: number[]; // snapshot of genre filter at cache time
scrollTop: number;
schemaVersion?: number;
}
export type HomeCacheStatus = 'fresh' | 'stale' | 'empty';
@@ -62,6 +63,13 @@ export type HomeCacheStatus = 'fresh' | 'stale' | 'empty';
const FRESH_TTL_MS = 5 * 60 * 1000; // 5 minutes
const MAX_TTL_MS = 60 * 60 * 1000; // 60 minutes
const SESSION_KEY = 'qbz-home-cache';
/**
* Bump whenever the shape of HomeCacheData or AlbumCardData changes,
* so stale sessionStorage entries from older builds are discarded
* instead of being restored with missing fields (which caused the
* ribbon field to show up as undefined on cache-fresh loads).
*/
const CACHE_SCHEMA_VERSION = 2;
let cache: HomeCacheData | null = null;
@@ -70,7 +78,13 @@ function restoreFromSession(): void {
try {
const stored = sessionStorage.getItem(SESSION_KEY);
if (stored) {
cache = JSON.parse(stored);
const parsed = JSON.parse(stored);
if (parsed?.schemaVersion === CACHE_SCHEMA_VERSION) {
cache = parsed;
} else {
// Older schema — drop it so loadHome() runs fresh.
try { sessionStorage.removeItem(SESSION_KEY); } catch {}
}
}
} catch {
// sessionStorage not available or corrupted
@@ -129,7 +143,8 @@ export function setHomeCache(data: Omit<HomeCacheData, 'timestamp' | 'scrollTop'
...data,
timestamp: Date.now(),
scrollTop: cache?.scrollTop ?? 0,
};
schemaVersion: CACHE_SCHEMA_VERSION,
} as HomeCacheData;
persistToSession();
}