Auto-schedule daily discovery + fix Find More UX + expand query diversity
Auto-discovery daemon: - Runs every hour, triggers full discovery for any user whose last run was >23 hours ago. First check is 5 minutes after startup. - Tracks run time in user_settings.last_discovery_run (new column). - Manual Find More also stamps last_discovery_run. Discovery status endpoint (GET /api/discovery/status): - Returns pending_count (unseen queue size) and last_run timestamp. - Shown in the Discover page header so users know queue state at a glance. Find More UX fix: - Was: kick background task, wait 8 seconds, refetch (task takes minutes). - Now: button shows "Queued ✓" on success with an explanatory banner telling the user it takes a few minutes and also runs daily automatically. Query diversity: - Added "best [category] channels" serendipity queries to crawl_by_search. - Limit raised from 25 to 30 queries per run. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -170,10 +170,17 @@ def refresh_discovery(
|
||||
user_id = current_user.id
|
||||
|
||||
def _run_discovery():
|
||||
from datetime import datetime
|
||||
from ..database import SessionLocal
|
||||
from sqlalchemy import text as _text
|
||||
fresh_db = SessionLocal()
|
||||
try:
|
||||
run_full_discovery(fresh_db, user_id, regions)
|
||||
fresh_db.execute(
|
||||
_text("UPDATE user_settings SET last_discovery_run = :now WHERE user_id = :uid"),
|
||||
{"now": datetime.utcnow(), "uid": user_id},
|
||||
)
|
||||
fresh_db.commit()
|
||||
finally:
|
||||
fresh_db.close()
|
||||
|
||||
@@ -251,6 +258,23 @@ def dismiss_discovery_video(
|
||||
db.commit()
|
||||
|
||||
|
||||
@router.get("/status")
|
||||
def discovery_status(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
from ..models import UserSettings
|
||||
s = db.query(UserSettings).filter_by(user_id=current_user.id).first()
|
||||
pending = db.execute(
|
||||
text("SELECT COUNT(*) AS n FROM discovery_queue WHERE user_id = :uid AND seen = 0"),
|
||||
{"uid": current_user.id},
|
||||
).mappings().first()
|
||||
return {
|
||||
"last_run": s.last_discovery_run.isoformat() if s and s.last_discovery_run else None,
|
||||
"pending_count": pending["n"] if pending else 0,
|
||||
}
|
||||
|
||||
|
||||
@router.get("/community", response_model=list[dict])
|
||||
def community_shelf(
|
||||
db: Session = Depends(get_db),
|
||||
|
||||
Reference in New Issue
Block a user