feat(channels): kick recent backfill immediately on 'full history' opt-in

When a user requests full history for a channel whose recent uploads aren't
fetched yet, run a one-channel recent backfill synchronously in the request so
the feed populates at once instead of waiting for the scheduler. Deep paging
still follows on the scheduler (recent-then-deep). The deep-toggle mutation now
also refreshes my-status and the feed.
This commit is contained in:
npeter83 2026-06-12 00:00:50 +02:00
parent 7c04bc1ee8
commit 6561738502
2 changed files with 22 additions and 2 deletions

View file

@ -8,6 +8,7 @@ from sqlalchemy.orm import Session
from app.auth import current_user, has_write_scope
from app.db import get_db
from app.models import Channel, ChannelTag, Subscription, Tag, User, Video
from app.sync.runner import run_recent_backfill
from app.youtube.client import YouTubeClient, YouTubeError
router = APIRouter(prefix="/api/channels", tags=["channels"])
@ -84,6 +85,8 @@ def update_channel(
db: Session = Depends(get_db),
) -> dict:
sub = _user_subscription(db, user, channel_id)
channel = db.get(Channel, channel_id)
deep_turned_on = False
if "priority" in payload:
sub.priority = int(payload["priority"])
if "hidden" in payload:
@ -92,13 +95,23 @@ def update_channel(
# Opt this channel into (or out of) full-history backfill. The deep scheduler
# picks the flag up on its next run; turning it off won't undo already-fetched
# videos, it just stops further deep paging if nobody else still wants it.
sub.deep_requested = bool(payload["deep_requested"])
want = bool(payload["deep_requested"])
deep_turned_on = want and not sub.deep_requested
sub.deep_requested = want
db.commit()
# Opting a channel into full history should give an immediate feed: if we haven't even
# fetched its recent uploads yet, do that one channel now (cheap) instead of waiting for
# the scheduler. Deep paging still follows on the scheduler's next run (recent-then-deep).
if deep_turned_on and channel is not None and channel.recent_synced_at is None:
run_recent_backfill(db, [channel], max_channels=1)
return {
"id": channel_id,
"priority": sub.priority,
"hidden": sub.hidden,
"deep_requested": sub.deep_requested,
"recent_synced": channel.recent_synced_at is not None if channel else None,
}