Add skip_cache param to get_artist_albums for watchlist scans

The watchlist auto-scan needs fresh data from Spotify to detect new
releases, so it bypasses the cache added in the previous commit.
All other callers (UI browsing, completion badges, discography views)
continue to benefit from cached results.
This commit is contained in:
Broque Thomas 2026-03-31 21:59:46 -07:00
parent 62da959889
commit a7ebde8c01
2 changed files with 13 additions and 10 deletions

View file

@ -1305,19 +1305,22 @@ class SpotifyClient:
return None
@rate_limited
def get_artist_albums(self, artist_id: str, album_type: str = 'album,single', limit: int = 10) -> List[Album]:
"""Get albums by artist ID - falls back to iTunes if Spotify not authenticated"""
# Check cache first — keyed by artist_id + album_type
def get_artist_albums(self, artist_id: str, album_type: str = 'album,single', limit: int = 10, skip_cache: bool = False) -> List[Album]:
"""Get albums by artist ID - falls back to iTunes if Spotify not authenticated.
Set skip_cache=True for watchlist scans that need fresh data to detect new releases."""
cache = get_metadata_cache()
fallback_src = self._fallback_source
source = fallback_src if self._is_itunes_id(artist_id) else 'spotify'
cache_key = f"{artist_id}_albums_{album_type.replace(',', '_')}"
cached = cache.get_entity(source, 'artist', cache_key)
if cached:
try:
return [Album.from_spotify_album(ad) for ad in cached]
except Exception:
pass # Cache data incompatible, re-fetch
# Check cache first (unless caller needs fresh data)
if not skip_cache:
cached = cache.get_entity(source, 'artist', cache_key)
if cached:
try:
return [Album.from_spotify_album(ad) for ad in cached]
except Exception:
pass # Cache data incompatible, re-fetch
if self.is_spotify_authenticated():
try:

View file

@ -42891,7 +42891,7 @@ def playlist_explorer_build_tree():
# Fetch albums
try:
all_albums = active_client.get_artist_albums(artist_id, album_type='album,single', limit=50)
all_albums = active_client.get_artist_albums(artist_id, album_type='album,single', limit=50, skip_cache=True)
except Exception as e:
return {'success': False, 'error': f'Album fetch failed: {e}'}