Skip to content

Sources: enabling a feed triggers an immediate sync (#195)#198

Merged
jozef2svrcek merged 3 commits into
mainfrom
feed-immediate-sync-on-enable-195
Jul 25, 2026
Merged

Sources: enabling a feed triggers an immediate sync (#195)#198
jozef2svrcek merged 3 commits into
mainfrom
feed-immediate-sync-on-enable-195

Conversation

@jozef2svrcek

Copy link
Copy Markdown
Contributor

Closes #195.

Enabling TWIC or Lichess Broadcasts now kicks off a download+import immediately instead of only becoming eligible for the scheduler's next tick — fixing the "I enabled it, nothing happened" feel.

How

The POST /sources/{key}/enabled quick-mutation (from #191) submits a sources_sync after the enable write, when all hold:

Maintenance after the import is size-matched (the decided option) — sources_sync already requests full for a bulk import and the light pass for a feed.

Avoiding a double-import during onboarding

A new sync flag on the endpoint (default true) lets the wizard opt out: its own first-run pipeline (startSetup) does the initial load, so applySourceSelection passes sync=false. The sentinel guard is a second line of defence (covers a resume too).

Verified

Live test: POST /sources/twic/enabled {sync:true} → a running sources_sync twic job appears immediately. (sync=false and bulk sources are guarded by simple boolean checks and submit nothing.)

Build + clippy (-D warnings) + 45 chess-db tests green; frontend builds.

🤖 Generated with Claude Code

https://claude.ai/code/session_019KdPPg7P3bZ5p2RRhZZcv2

jozef2svrcek and others added 3 commits July 25, 2026 13:47
Enabling TWIC or Lichess Broadcasts now kicks off a download+import right
away instead of only becoming eligible for the scheduler's next tick — so
it no longer feels like "I enabled it, nothing happened."

The `POST /sources/{key}/enabled` quick-mutation submits a `sources_sync`
for the source after the enable write, when:
- it's a feed (bulk sources like Ajedrez get their own one-shot action, #196),
- a sync isn't already queued/running for it, and
- no first-run pipeline owns the database (setup sentinel absent).

Maintenance after the import is size-matched, which `sources_sync` already
does (full for bulk, light for a feed).

A new `sync` flag on the endpoint (default true) lets the wizard opt out:
its own first-run pipeline does the initial load, so `applySourceSelection`
now passes sync=false to avoid double-importing.

Verified live: enabling TWIC submits a running `sources_sync twic`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019KdPPg7P3bZ5p2RRhZZcv2
)

Two follow-ups from testing:

1. Enabling a second feed while the first was still importing left its
   toggle greyed and its sync unqueued until the first finished. The enable
   endpoint's state write serializes on the single writer behind the running
   import, and it was awaited (blocking the HTTP response, hence the toggle)
   AND the sync was submitted only after that write. Now: submit the sync
   first (so it queues immediately, behind the running one), then apply the
   enable write fire-and-forget (`spawn_fn`) on the interactive path so the
   response returns at once. The wizard path (sync=false) still awaits — the
   writer is idle there and `startSetup` reads the enabled set right after,
   so the write must be committed first. Verified live: a second enable
   returns in <1ms while the first syncs, and its sources_sync is queued.

2. The wizard's first-run pipeline submitted a "Download <src>" + "Import
   <src>" pair per source, while enabling from Maintenance submits one
   "Sync <src>" (sources_sync). Unify: the wizard now submits sources_sync
   too, so onboarding shows the same single job. First-run still gets the
   full identity-first maintenance (request_maintenance(true) upfront,
   coalesced with each sync's request).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019KdPPg7P3bZ5p2RRhZZcv2
The immediate-sync was gated on `!setup_sentinel_present`, so re-enabling a
feed via Maintenance while the wizard's first-run pipeline was still running
did nothing — no job queued. The guard was redundant (the wizard's own
enables pass sync=false) and harmful: the scheduler is held off during
first-run, so the interactive enable is the only path that would queue a
sync. Drop the sentinel gate; the sync=false (wizard) and already-syncing
(dedup) checks already prevent double-imports.

Verified live: with a setup sentinel present, enabling a feed now submits
its sources_sync.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019KdPPg7P3bZ5p2RRhZZcv2
@jozef2svrcek
jozef2svrcek merged commit 40347ba into main Jul 25, 2026
6 checks passed
jozef2svrcek added a commit that referenced this pull request Jul 25, 2026
…jedrez, per-card metrics + incremental dedup

Lands the tested batch behind the 0.9.9 draft:

- #194 (PR #200): configurable daily update-check time + next-run visibility.
- #195 (PR #198): enabling a feed triggers an immediate sync.
- #196 (PR #199): Ajedrez one-shot "Download & import" action instead of a toggle.
- #197 (PR #201): per-source metrics moved into each card; aggregated blocks dropped.
- PR #203: crisp high-contrast toggle icon.

Plus follow-up work validated during testing:
- Incremental dedup_games via a `deduped` marker; unified single maintenance pass
  (supersedes the closed PR #204).
- Sync init shows the indeterminate bar instead of a stuck 100%.
- Enable-flag write persists before the sync is dispatched; toggle state derived
  from the job pipeline + a module-level intent store, so it survives navigation.
- FIDE card reflects background (scheduler / post-sync) refreshes.
- Coalesced maintenance is pinned to the queue tail the moment a feed is enabled.
@jozef2svrcek
jozef2svrcek deleted the feed-immediate-sync-on-enable-195 branch July 25, 2026 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sources: enabling a feed triggers an immediate sync (download+import)

1 participant