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:
@@ -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))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user