feat: replace ~50 IPC calls with single reco_get_home_resolved invoke

HomeView ML sections now use a single IPC call that returns fully
resolved card data from Rust. The 3-tier cache (reco meta → API cache
→ Qobuz API) handles all resolution server-side, eliminating the
per-item fetch loop on the frontend.

Genre filtering and section visibility still applied client-side.
Existing fetchAlbums/fetchTracks/fetchArtists kept for other uses.
This commit is contained in:
vicrodh committed 2026-02-09 10:44:42 -06:00
1 parent ee8cd286f3
commit a91c955ee4
1 file changed
+23 -56
+23 -56
View File
@@ -59,14 +59,6 @@
playCount: number; playCount: number;
} }
interface HomeSeeds {
recentlyPlayedAlbumIds: string[];
continueListeningTrackIds: number[];
topArtistIds: TopArtistSeed[];
favoriteAlbumIds: string[];
favoriteTrackIds: number[];
}
interface AlbumCardData { interface AlbumCardData {
id: string; id: string;
artwork: string; artwork: string;
@@ -85,6 +77,13 @@
playCount?: number; playCount?: number;
} }
interface HomeResolved {
recentlyPlayedAlbums: AlbumCardData[];
continueListeningTracks: DisplayTrack[];
topArtists: ArtistCardData[];
favoriteAlbums: AlbumCardData[];
}
interface Props { interface Props {
userName?: string; userName?: string;
onAlbumClick?: (albumId: string) => void; onAlbumClick?: (albumId: string) => void;
@@ -776,7 +775,8 @@
// 2. ML seeds from local SQLite -> user-specific sections // 2. ML seeds from local SQLite -> user-specific sections
const discoverPromise = fetchAllDiscoverData(genreIds); const discoverPromise = fetchAllDiscoverData(genreIds);
const mlPromise = invoke<HomeSeeds>('reco_get_home_ml', { // Single IPC call returns fully-resolved card data (3-tier cache in Rust)
const mlPromise = invoke<HomeResolved>('reco_get_home_resolved', {
limitRecentAlbums: homeLimits.recentAlbums, limitRecentAlbums: homeLimits.recentAlbums,
limitContinueTracks: homeLimits.continueTracks, limitContinueTracks: homeLimits.continueTracks,
limitTopArtists: homeLimits.topArtists, limitTopArtists: homeLimits.topArtists,
@@ -784,81 +784,48 @@
}); });
try { try {
// Wait for ML seeds (local data) const resolved = await mlPromise;
const seeds = await mlPromise;
// Load ML-based sections in parallel // Recently Played Albums
// Continue Listening (tracks)
if (isSectionVisible('continueTracks')) {
fetchTracks(seeds.continueListeningTrackIds).then(tracks => {
continueTracks = tracks;
loadingContinueTracks = false;
}).catch(err => {
console.error('Failed to load continueTracks:', err);
loadingContinueTracks = false;
});
} else {
loadingContinueTracks = false;
}
// Recently Played (albums) - start immediately with seeds
if (isSectionVisible('recentAlbums')) { if (isSectionVisible('recentAlbums')) {
const recentAlbumIds = normalizeAlbumIds(seeds.recentlyPlayedAlbumIds); const filtered = filterAlbumsByGenre(resolved.recentlyPlayedAlbums).slice(0, homeLimits.recentAlbums);
// Fetch more if filtering, to have enough after filter
const fetchLimit = hasGenreFilter() ? homeLimits.recentAlbums * 3 : homeLimits.recentAlbums;
fetchAlbums(recentAlbumIds.slice(0, fetchLimit)).then(async (albums) => {
const filtered = filterAlbumsByGenre(albums).slice(0, homeLimits.recentAlbums);
recentAlbums = filtered; recentAlbums = filtered;
loadingRecentAlbums = false; loadingRecentAlbums = false;
await tick(); await tick();
loadAllAlbumDownloadStatuses(filtered).catch(() => {}); loadAllAlbumDownloadStatuses(filtered).catch(() => {});
}).catch(err => {
console.error('Failed to load recentAlbums:', err);
loadingRecentAlbums = false;
});
} else { } else {
loadingRecentAlbums = false; loadingRecentAlbums = false;
} }
// Continue Listening Tracks
if (isSectionVisible('continueTracks')) {
continueTracks = resolved.continueListeningTracks;
loadingContinueTracks = false;
} else {
loadingContinueTracks = false;
}
// Top Artists // Top Artists
if (isSectionVisible('topArtists')) { if (isSectionVisible('topArtists')) {
fetchArtists(seeds.topArtistIds.slice(0, homeLimits.topArtists)).then(artists => { topArtists = resolved.topArtists;
topArtists = artists;
loadingTopArtists = false; loadingTopArtists = false;
}).catch(err => {
console.error('Failed to load topArtists:', err);
loadingTopArtists = false;
});
} else { } else {
loadingTopArtists = false; loadingTopArtists = false;
} }
// Favorite Albums // Favorite Albums
if (isSectionVisible('favoriteAlbums')) { if (isSectionVisible('favoriteAlbums')) {
// Get favorite track details to extract album IDs const filtered = filterAlbumsByGenre(resolved.favoriteAlbums).slice(0, homeLimits.favoriteAlbums);
fetchTracks(seeds.favoriteTrackIds.slice(0, homeLimits.favoriteTracks)).then(async favoriteTrackDetails => {
const favoriteAlbumIds = normalizeAlbumIds([
...seeds.favoriteAlbumIds,
...favoriteTrackDetails.map(track => track.albumId)
]);
// Fetch more if filtering, to have enough after filter
const fetchLimit = hasGenreFilter() ? homeLimits.favoriteAlbums * 3 : homeLimits.favoriteAlbums;
const albums = await fetchAlbums(favoriteAlbumIds.slice(0, fetchLimit));
const filtered = filterAlbumsByGenre(albums).slice(0, homeLimits.favoriteAlbums);
favoriteAlbums = filtered; favoriteAlbums = filtered;
loadingFavoriteAlbums = false; loadingFavoriteAlbums = false;
await tick(); await tick();
loadAllAlbumDownloadStatuses(filtered).catch(() => {}); loadAllAlbumDownloadStatuses(filtered).catch(() => {});
}).catch(err => {
console.error('Failed to load favoriteAlbums:', err);
loadingFavoriteAlbums = false;
});
} else { } else {
loadingFavoriteAlbums = false; loadingFavoriteAlbums = false;
} }
} catch (err) { } catch (err) {
console.error('ML seeds failed:', err); console.error('Home resolved failed:', err);
error = String(err); error = String(err);
loadingRecentAlbums = false; loadingRecentAlbums = false;
loadingContinueTracks = false; loadingContinueTracks = false;