perf: parallelize artist resolution and use small images for cards
Resolve albums, tracks, and artists concurrently with tokio::try_join instead of sequentially. Artists were waiting behind album/track resolution unnecessarily. Also change get_image() to prefer small (230px) over large (600px) for card contexts, reducing download size.
This commit is contained in:
1 file changed
+16
-18
@@ -582,10 +582,10 @@ fn format_quality(hires: bool, bit_depth: Option<u32>, sampling_rate: Option<f64
|
|||||||
|
|
||||||
fn get_image(image: &ImageSet) -> String {
|
fn get_image(image: &ImageSet) -> String {
|
||||||
image
|
image
|
||||||
.large
|
.small
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
.or(image.large.as_ref())
|
||||||
.or(image.thumbnail.as_ref())
|
.or(image.thumbnail.as_ref())
|
||||||
.or(image.small.as_ref())
|
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
@@ -794,17 +794,25 @@ pub async fn reco_get_home_resolved(
|
|||||||
.map(|s| (s.artist_id, s.play_count))
|
.map(|s| (s.artist_id, s.play_count))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Step 3: Resolve albums (recent + favorite)
|
// Step 3: Resolve albums, tracks, AND artists in parallel
|
||||||
let recently_played_albums = resolve_albums(
|
// Artists are independent of albums/tracks, so start them concurrently.
|
||||||
|
let albums_fut = resolve_albums(
|
||||||
&seeds.recently_played_album_ids,
|
&seeds.recently_played_album_ids,
|
||||||
&reco_state,
|
&reco_state,
|
||||||
&app_state,
|
&app_state,
|
||||||
&cache_state,
|
&cache_state,
|
||||||
)
|
);
|
||||||
.await?;
|
let tracks_fut = resolve_tracks(&all_track_ids, &reco_state, &app_state, &cache_state);
|
||||||
|
let artists_fut = resolve_artists(
|
||||||
|
&all_artist_ids,
|
||||||
|
&artist_play_counts,
|
||||||
|
&reco_state,
|
||||||
|
&app_state,
|
||||||
|
&cache_state,
|
||||||
|
);
|
||||||
|
|
||||||
// Step 4: Resolve tracks (continue + favorite)
|
let (recently_played_albums, all_tracks, top_artists) =
|
||||||
let all_tracks = resolve_tracks(&all_track_ids, &reco_state, &app_state, &cache_state).await?;
|
tokio::try_join!(albums_fut, tracks_fut, artists_fut)?;
|
||||||
|
|
||||||
// Build track lookup
|
// Build track lookup
|
||||||
let track_map: HashMap<u64, &TrackDisplayMeta> =
|
let track_map: HashMap<u64, &TrackDisplayMeta> =
|
||||||
@@ -943,16 +951,6 @@ pub async fn reco_get_home_resolved(
|
|||||||
all_albums
|
all_albums
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 6: Resolve artists
|
|
||||||
let top_artists = resolve_artists(
|
|
||||||
&all_artist_ids,
|
|
||||||
&artist_play_counts,
|
|
||||||
&reco_state,
|
|
||||||
&app_state,
|
|
||||||
&cache_state,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(HomeResolved {
|
Ok(HomeResolved {
|
||||||
recently_played_albums,
|
recently_played_albums,
|
||||||
continue_listening_tracks,
|
continue_listening_tracks,
|
||||||
|
|||||||
Reference in new issue
Block a user