Update to artist credit handling

This commit is contained in:
Connor Johnstone
2026-03-18 14:34:58 -04:00
parent a268ec4e56
commit 8b16859526
10 changed files with 181 additions and 60 deletions

View File

@@ -148,6 +148,7 @@ async fn get_cached_album_tracks(
rg_id: &str,
first_release_id: Option<&str>,
ttl_seconds: i64,
extend_ttl: bool,
) -> Result<CachedAlbumTracks, ApiError> {
let cache_key = format!("artist_rg_tracks:{rg_id}");
@@ -156,6 +157,10 @@ async fn get_cached_album_tracks(
.map_err(|e| ApiError::Internal(e.to_string()))?
{
if let Ok(cached) = serde_json::from_str::<CachedAlbumTracks>(&json) {
// Extend TTL if artist is now watched (upgrades 7-day browse cache to permanent)
if extend_ttl {
let _ = queries::cache::set(state.db.conn(), &cache_key, "musicbrainz", &json, ttl_seconds).await;
}
return Ok(cached);
}
}
@@ -353,13 +358,15 @@ async fn get_artist_full(
// If artist has any watched items, cache permanently (10 years);
// otherwise cache for 7 days (just browsing)
let cache_ttl = if artist_wanted.is_empty() { 7 * 86400 } else { 10 * 365 * 86400 };
let is_watched = !artist_wanted.is_empty();
let cache_ttl = if is_watched { 10 * 365 * 86400 } else { 7 * 86400 };
let cached = match get_cached_album_tracks(
&state,
&rg.id,
rg.first_release_id.as_deref(),
cache_ttl,
is_watched,
).await {
Ok(c) => c,
Err(e) => {