Auto-reindex channel on page visit if stale

GET /channels/{id} now fires a background _index_channel_task if the
channel hasn't been crawled in the last hour. The frontend refetches
channel + videos 8s after page load to pick up the updated data.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-26 22:02:59 +02:00
parent 871f668525
commit d740fd5224
2 changed files with 24 additions and 1 deletions

View File

@@ -546,6 +546,7 @@ def bulk_channel_action(
@router.get("/{channel_id}", response_model=ChannelOut)
def get_channel(
channel_id: int,
background_tasks: BackgroundTasks,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
@@ -576,6 +577,16 @@ def get_channel(
).mappings().first()
if not row:
raise HTTPException(status_code=404, detail="Channel not found")
# Re-index in the background if stale (not crawled in the last hour)
crawled_at = row.get("crawled_at")
stale = (
crawled_at is None
or (datetime.utcnow() - crawled_at).total_seconds() > 3600
)
if stale:
background_tasks.add_task(_index_channel_task, channel_id, current_user.id)
return ChannelOut(**dict(row))