added the watch/unwatch buttons for artists/albums
This commit is contained in:
+17
-7
@@ -95,9 +95,11 @@ async fn list_artists(
|
||||
auth::require_auth(&session)?;
|
||||
let artists = queries::artists::list(state.db.conn(), query.limit, query.offset).await?;
|
||||
|
||||
let wanted = queries::wanted::list(state.db.conn(), None, None).await?;
|
||||
|
||||
let mut items: Vec<ArtistListItem> = Vec::new();
|
||||
for a in &artists {
|
||||
// Check if we have cached artist-level totals from a prior detail page load
|
||||
// Get total_items from enrichment cache (total available tracks from MB)
|
||||
let cache_key = format!("artist_totals:{}", a.id);
|
||||
let cached_totals: Option<(u32, u32, u32)> =
|
||||
if let Ok(Some(json)) = queries::cache::get(state.db.conn(), &cache_key).await {
|
||||
@@ -107,12 +109,20 @@ async fn list_artists(
|
||||
};
|
||||
|
||||
let enriched = cached_totals.is_some();
|
||||
let (total_watched, total_owned, total_items) =
|
||||
if let Some((avail, watched, owned)) = cached_totals {
|
||||
(watched as usize, owned as usize, avail as usize)
|
||||
} else {
|
||||
(0, 0, 0)
|
||||
};
|
||||
let total_items = cached_totals
|
||||
.map(|(avail, _, _)| avail as usize)
|
||||
.unwrap_or(0);
|
||||
|
||||
// Compute watched/owned live from wanted_items (always current)
|
||||
let artist_wanted: Vec<_> = wanted
|
||||
.iter()
|
||||
.filter(|w| w.artist_id == Some(a.id))
|
||||
.collect();
|
||||
let total_watched = artist_wanted.len();
|
||||
let total_owned = artist_wanted
|
||||
.iter()
|
||||
.filter(|w| w.status == WantedStatus::Owned)
|
||||
.count();
|
||||
|
||||
items.push(ArtistListItem {
|
||||
id: a.id,
|
||||
|
||||
Reference in New Issue
Block a user