Reset watchlist scan timestamps on clear/period change
When clearing the wishlist or changing the discovery lookback period, reset watchlist_artists.last_scan_timestamp to NULL so subsequent scans can re-discover older releases that were previously filtered by an earlier scan timestamp. clear_wishlist now deletes wishlist_tracks, updates last_scan_timestamp for all watchlist artists, and logs the number of tracks cleared and artists reset. set_discovery_lookback_period also resets last_scan_timestamp and reports how many artists were reset. Minor whitespace cleanups in watchlist_scanner and web_server included.
This commit is contained in:
parent
7eee2be38c
commit
81617b06aa
3 changed files with 17 additions and 5 deletions
|
|
@ -763,7 +763,7 @@ class WatchlistScanner:
|
||||||
|
|
||||||
# Return all albums if no cutoff (lookback_period = 'all')
|
# Return all albums if no cutoff (lookback_period = 'all')
|
||||||
return albums
|
return albums
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error getting discography for artist {spotify_artist_id}: {e}")
|
logger.error(f"Error getting discography for artist {spotify_artist_id}: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
|
|
@ -3544,13 +3544,19 @@ class MusicDatabase:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def clear_wishlist(self) -> bool:
|
def clear_wishlist(self) -> bool:
|
||||||
"""Clear all tracks from the wishlist"""
|
"""Clear all tracks from the wishlist and reset scan timestamps so next scan re-discovers everything"""
|
||||||
try:
|
try:
|
||||||
with self._get_connection() as conn:
|
with self._get_connection() as conn:
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("DELETE FROM wishlist_tracks")
|
cursor.execute("DELETE FROM wishlist_tracks")
|
||||||
|
cleared_count = cursor.rowcount
|
||||||
|
# Reset last_scan_timestamp on all watchlist artists so the next scan
|
||||||
|
# uses the lookback period setting (e.g. "entire discography") instead
|
||||||
|
# of only finding albums released after the old scan date
|
||||||
|
cursor.execute("UPDATE watchlist_artists SET last_scan_timestamp = NULL")
|
||||||
|
reset_count = cursor.rowcount
|
||||||
conn.commit()
|
conn.commit()
|
||||||
logger.info(f"Cleared {cursor.rowcount} tracks from wishlist")
|
logger.info(f"Cleared {cleared_count} tracks from wishlist, reset scan timestamps on {reset_count} artists")
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error clearing wishlist: {e}")
|
logger.error(f"Error clearing wishlist: {e}")
|
||||||
|
|
|
||||||
|
|
@ -11623,9 +11623,15 @@ def set_discovery_lookback_period():
|
||||||
INSERT OR REPLACE INTO metadata (key, value, updated_at)
|
INSERT OR REPLACE INTO metadata (key, value, updated_at)
|
||||||
VALUES ('discovery_lookback_period', ?, CURRENT_TIMESTAMP)
|
VALUES ('discovery_lookback_period', ?, CURRENT_TIMESTAMP)
|
||||||
""", (period,))
|
""", (period,))
|
||||||
|
|
||||||
|
# When expanding the lookback window (especially to "entire disco"),
|
||||||
|
# reset scan timestamps so the next scan re-discovers older releases
|
||||||
|
# that were filtered out under the previous narrower setting
|
||||||
|
cursor.execute("UPDATE watchlist_artists SET last_scan_timestamp = NULL")
|
||||||
|
reset_count = cursor.rowcount
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
print(f"✅ Discovery lookback period set to: {period}")
|
print(f"✅ Discovery lookback period set to: {period}, reset scan timestamps on {reset_count} artists")
|
||||||
return jsonify({"success": True, "period": period})
|
return jsonify({"success": True, "period": period})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -20153,7 +20159,7 @@ def start_watchlist_scan():
|
||||||
|
|
||||||
# Get artist discography using provider-aware method
|
# Get artist discography using provider-aware method
|
||||||
albums = scanner.get_artist_discography_for_watchlist(artist, artist.last_scan_timestamp)
|
albums = scanner.get_artist_discography_for_watchlist(artist, artist.last_scan_timestamp)
|
||||||
|
|
||||||
if albums is None:
|
if albums is None:
|
||||||
scan_results.append(type('ScanResult', (), {
|
scan_results.append(type('ScanResult', (), {
|
||||||
'artist_name': artist.artist_name,
|
'artist_name': artist.artist_name,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue