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:
Broque Thomas 2026-02-23 16:47:04 -08:00
parent 7eee2be38c
commit 81617b06aa
3 changed files with 17 additions and 5 deletions

View file

@ -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}")

View file

@ -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: