feat(discover): full reset — clear + rebuild suggestions
POST /api/discover/reset sets discover.resetRequested; the worker, at the start of the next sweep, clears all PENDING suggestions + contributions + seed throttles and nulls WatchedArtist.lastDiscoveredAt (keeping followed/wanted/dismissed decisions), then regenerates everything with current logic. A 'Reset' button on /discover (2-step confirm) triggers it. worker 247, web 190 tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -315,6 +315,18 @@ def _recompute_suggestions(conn: psycopg.Connection, affected: set[str],
|
||||
return surfaced
|
||||
|
||||
|
||||
def reset_pending(conn: psycopg.Connection) -> None:
|
||||
"""Clear discovery state so the next sweep rebuilds from scratch with current logic. Drops
|
||||
all PENDING suggestions (followed/wanted/dismissed user decisions are kept), every seed
|
||||
contribution + library-seed throttle, and marks each watched artist due again."""
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("DELETE FROM \"DiscoverySuggestion\" WHERE status = 'pending'")
|
||||
cur.execute('DELETE FROM "DiscoverySeedContribution"')
|
||||
cur.execute('DELETE FROM "DiscoverySeed"')
|
||||
cur.execute('UPDATE "WatchedArtist" SET "lastDiscoveredAt" = NULL')
|
||||
conn.commit()
|
||||
|
||||
|
||||
def run_discovery(conn: psycopg.Connection, sources: list[SimilaritySource],
|
||||
browser: MbBrowser, cfg: DiscoveryConfig, popularity=None) -> DiscoveryResult:
|
||||
"""Record each seed's similar-artist contributions, then recompute affected
|
||||
|
||||
@@ -10,7 +10,7 @@ from lyra_worker.claim import claim_next, reclaim_stuck_jobs
|
||||
from lyra_worker.config import get_config
|
||||
from lyra_worker.crypto import secret_key_problem
|
||||
from lyra_worker.db import wait_for_db
|
||||
from lyra_worker.discovery import DiscoveryConfig, DiscoveryResult, run_discovery
|
||||
from lyra_worker.discovery import DiscoveryConfig, DiscoveryResult, reset_pending, run_discovery
|
||||
from lyra_worker.library import clear_staging_root
|
||||
from lyra_worker.monitor import MonitorConfig, fulfill_owned_releases, reconcile, sweep
|
||||
from lyra_worker.pipeline import run_pipeline
|
||||
@@ -147,6 +147,10 @@ def maybe_run_discovery(conn, sources, browser, config, dcfg, now, last_discover
|
||||
|
||||
starting = not in_progress
|
||||
if starting: # begin a fresh sweep
|
||||
if str(config.get("discover.resetRequested", "")).strip().lower() in _TRUE:
|
||||
reset_pending(conn) # wipe stale pending suggestions before rebuilding
|
||||
_set_config(conn, "discover.resetRequested", "false")
|
||||
print("worker: discovery reset — cleared pending suggestions, rebuilding", flush=True)
|
||||
_set_config(conn, "discover.inProgress", "true")
|
||||
_set_config(conn, "discover.requested", "false")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user