Fixed issue where itunes only watchlist artists would update the 'last scanned' property after watchlist scan

This commit is contained in:
Broque Thomas 2026-02-13 16:10:19 -08:00
parent 5c6c51061a
commit d907558abf
3 changed files with 37 additions and 22 deletions

View file

@ -676,9 +676,8 @@ class WatchlistScanner:
logger.warning(f"Error checking album {album.name}: {e}") logger.warning(f"Error checking album {album.name}: {e}")
continue continue
# Update last scan timestamp for this artist (use spotify_artist_id as DB key for consistency) # Update last scan timestamp for this artist
db_artist_id = watchlist_artist.spotify_artist_id or artist_id self.update_artist_scan_timestamp(watchlist_artist)
self.update_artist_scan_timestamp(db_artist_id)
# Fetch and store similar artists for discovery feature (with caching to avoid over-polling) # Fetch and store similar artists for discovery feature (with caching to avoid over-polling)
# Similar artists are fetched from MusicMap (works with any source) and matched to both Spotify and iTunes # Similar artists are fetched from MusicMap (works with any source) and matched to both Spotify and iTunes
@ -1203,29 +1202,45 @@ class WatchlistScanner:
logger.error(f"Error adding track to wishlist: {track_name}: {e}") logger.error(f"Error adding track to wishlist: {track_name}: {e}")
return False return False
def update_artist_scan_timestamp(self, spotify_artist_id: str) -> bool: def update_artist_scan_timestamp(self, artist) -> bool:
"""Update the last scan timestamp for an artist""" """Update the last scan timestamp for an artist.
Args:
artist: WatchlistArtist object, or a string spotify_artist_id for backward compat
"""
try: try:
with self.database._get_connection() as conn: with self.database._get_connection() as conn:
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute(""" # Support both WatchlistArtist objects and raw string IDs
UPDATE watchlist_artists if hasattr(artist, 'id'):
SET last_scan_timestamp = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP # WatchlistArtist object - use database primary key (always reliable)
WHERE spotify_artist_id = ? cursor.execute("""
""", (spotify_artist_id,)) UPDATE watchlist_artists
SET last_scan_timestamp = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP
WHERE id = ?
""", (artist.id,))
artist_label = f"{artist.artist_name} (id={artist.id})"
else:
# Backward compat: raw string ID (try spotify, then itunes)
cursor.execute("""
UPDATE watchlist_artists
SET last_scan_timestamp = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP
WHERE spotify_artist_id = ? OR itunes_artist_id = ?
""", (artist, artist))
artist_label = f"ID {artist}"
conn.commit() conn.commit()
if cursor.rowcount > 0: if cursor.rowcount > 0:
logger.debug(f"Updated scan timestamp for artist {spotify_artist_id}") logger.debug(f"Updated scan timestamp for artist {artist_label}")
return True return True
else: else:
logger.warning(f"No artist found with Spotify ID {spotify_artist_id}") logger.warning(f"No artist found for {artist_label}")
return False return False
except Exception as e: except Exception as e:
logger.error(f"Error updating scan timestamp for artist {spotify_artist_id}: {e}") logger.error(f"Error updating scan timestamp: {e}")
return False return False
def _fetch_similar_artists_from_musicmap(self, artist_name: str, limit: int = 20) -> List[Dict[str, Any]]: def _fetch_similar_artists_from_musicmap(self, artist_name: str, limit: int = 20) -> List[Dict[str, Any]]:

View file

@ -247,7 +247,7 @@ class WatchlistScanWorker(QThread):
continue continue
# Update last scan timestamp # Update last scan timestamp
scanner.update_artist_scan_timestamp(watchlist_artist.spotify_artist_id) scanner.update_artist_scan_timestamp(watchlist_artist)
return ScanResult( return ScanResult(
artist_name=watchlist_artist.artist_name, artist_name=watchlist_artist.artist_name,

View file

@ -19013,7 +19013,7 @@ def start_watchlist_scan():
continue continue
# Update scan timestamp # Update scan timestamp
scanner.update_artist_scan_timestamp(artist.spotify_artist_id) scanner.update_artist_scan_timestamp(artist)
# Store result # Store result
scan_results.append(type('ScanResult', (), { scan_results.append(type('ScanResult', (), {
@ -19731,7 +19731,7 @@ def _process_watchlist_scan_automatically():
continue continue
# Update scan timestamp # Update scan timestamp
scanner.update_artist_scan_timestamp(artist.spotify_artist_id) scanner.update_artist_scan_timestamp(artist)
# Store result # Store result
scan_results.append(type('ScanResult', (), { scan_results.append(type('ScanResult', (), {