Compare commits
1 Commits
621355e352
...
75f3b4f704
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75f3b4f704 |
@@ -192,13 +192,30 @@ async fn get_cached_album_tracks(
|
|||||||
// Not cached — resolve release MBID and fetch tracks
|
// Not cached — resolve release MBID and fetch tracks
|
||||||
let release_mbid = if let Some(rid) = first_release_id {
|
let release_mbid = if let Some(rid) = first_release_id {
|
||||||
rid.to_string()
|
rid.to_string()
|
||||||
|
} else {
|
||||||
|
// Check DB cache for previously resolved release MBID
|
||||||
|
let resolve_cache_key = format!("release_for_rg:{rg_id}");
|
||||||
|
if let Ok(Some(cached_rid)) = queries::cache::get(state.db.conn(), &resolve_cache_key).await
|
||||||
|
{
|
||||||
|
cached_rid
|
||||||
} else {
|
} else {
|
||||||
// Browse releases for this release group (through shared rate limiter)
|
// Browse releases for this release group (through shared rate limiter)
|
||||||
state
|
let rid = state
|
||||||
.mb_client
|
.mb_client
|
||||||
.resolve_release_from_group(rg_id)
|
.resolve_release_from_group(rg_id)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| ApiError::Internal(format!("MB error for group {rg_id}: {e}")))?
|
.map_err(|e| ApiError::Internal(format!("MB error for group {rg_id}: {e}")))?;
|
||||||
|
// Cache the resolved release MBID for 365 days — it never changes
|
||||||
|
let _ = queries::cache::set(
|
||||||
|
state.db.conn(),
|
||||||
|
&resolve_cache_key,
|
||||||
|
"musicbrainz",
|
||||||
|
&rid,
|
||||||
|
365 * 86400,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
rid
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mb_tracks = state
|
let mb_tracks = state
|
||||||
@@ -259,7 +276,8 @@ pub async fn enrich_artist(
|
|||||||
quick_mode: bool,
|
quick_mode: bool,
|
||||||
) -> Result<serde_json::Value, ApiError> {
|
) -> Result<serde_json::Value, ApiError> {
|
||||||
// Resolve artist: local ID or MBID
|
// Resolve artist: local ID or MBID
|
||||||
let (artist, id, mbid) = if let Ok(local_id) = id_or_mbid.parse() {
|
// Track whether we already fetched artist info during resolution to avoid a duplicate API call
|
||||||
|
let (artist, id, mbid, prefetched_info) = if let Ok(local_id) = id_or_mbid.parse() {
|
||||||
let artist = queries::artists::get_by_id(state.db.conn(), local_id).await?;
|
let artist = queries::artists::get_by_id(state.db.conn(), local_id).await?;
|
||||||
let mbid = match &artist.musicbrainz_id {
|
let mbid = match &artist.musicbrainz_id {
|
||||||
Some(m) => m.clone(),
|
Some(m) => m.clone(),
|
||||||
@@ -274,7 +292,7 @@ pub async fn enrich_artist(
|
|||||||
})?
|
})?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(artist, Some(local_id), mbid)
|
(artist, Some(local_id), mbid, None)
|
||||||
} else {
|
} else {
|
||||||
let mbid = id_or_mbid.to_string();
|
let mbid = id_or_mbid.to_string();
|
||||||
|
|
||||||
@@ -288,9 +306,10 @@ pub async fn enrich_artist(
|
|||||||
|
|
||||||
if let Some(a) = local {
|
if let Some(a) = local {
|
||||||
let local_id = a.id;
|
let local_id = a.id;
|
||||||
(a, Some(local_id), mbid)
|
(a, Some(local_id), mbid, None)
|
||||||
} else {
|
} else {
|
||||||
// Look up artist info from MusicBrainz by MBID — don't create a local record
|
// Look up artist info from MusicBrainz by MBID — don't create a local record
|
||||||
|
// This fetches url-rels too, so we reuse it below instead of calling get_artist_info() again
|
||||||
let info =
|
let info =
|
||||||
state.mb_client.get_artist_info(&mbid).await.map_err(|e| {
|
state.mb_client.get_artist_info(&mbid).await.map_err(|e| {
|
||||||
ApiError::NotFound(format!("artist MBID {mbid} not found: {e}"))
|
ApiError::NotFound(format!("artist MBID {mbid} not found: {e}"))
|
||||||
@@ -307,12 +326,21 @@ pub async fn enrich_artist(
|
|||||||
monitored: false,
|
monitored: false,
|
||||||
last_checked_at: None,
|
last_checked_at: None,
|
||||||
};
|
};
|
||||||
(synthetic, None, mbid)
|
(synthetic, None, mbid, Some(info))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch detailed artist info (country, type, URLs) — best-effort
|
// Fetch detailed artist info (country, type, URLs) — reuse if already fetched during resolution
|
||||||
let artist_info = match state.mb_client.get_artist_info(&mbid).await {
|
let artist_info = if let Some(info) = prefetched_info {
|
||||||
|
tracing::debug!(
|
||||||
|
mbid = %mbid,
|
||||||
|
urls = info.urls.len(),
|
||||||
|
country = ?info.country,
|
||||||
|
"reusing prefetched artist info"
|
||||||
|
);
|
||||||
|
Some(info)
|
||||||
|
} else {
|
||||||
|
match state.mb_client.get_artist_info(&mbid).await {
|
||||||
Ok(info) => {
|
Ok(info) => {
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
mbid = %mbid,
|
mbid = %mbid,
|
||||||
@@ -326,6 +354,7 @@ pub async fn enrich_artist(
|
|||||||
tracing::warn!(mbid = %mbid, error = %e, "failed to fetch artist info");
|
tracing::warn!(mbid = %mbid, error = %e, "failed to fetch artist info");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch artist photo + bio + banner (cached, provider-aware)
|
// Fetch artist photo + bio + banner (cached, provider-aware)
|
||||||
|
|||||||
Reference in New Issue
Block a user