Skip to content

fix: throttle job state broadcasts to reduce dashboard query load#137

Open
salvageop wants to merge 1 commit into
masterfrom
fix/job-state-broadcast-throttle
Open

fix: throttle job state broadcasts to reduce dashboard query load#137
salvageop wants to merge 1 commit into
masterfrom
fix/job-state-broadcast-throttle

Conversation

@salvageop

Copy link
Copy Markdown
Collaborator

What

Telemetry.job_state_change_broadcast/4 fired a "job:state" broadcast on every Oban job start/stop/exception, and each broadcast causes every subscribed LiveView (HistoryTableLive, JobTableLive) to re-run its counts + paginated queries. With a busy download queue (fast indexing every 10 minutes, several concurrent yt-dlp workers), an open dashboard hammers SQLite with redundant reads — one full refresh per job event.

Fix

  • New PinchflatWeb.JobStateThrottle GenServer: telemetry casts to it, and it broadcasts at most once per second. Trailing-edge, so the final state of a burst is always reflected within a second — the dashboard's perceived behavior is unchanged.
  • JobTableLive.mount/3 now guards its subscription with connected?/1, matching the fix already applied to HistoryTableLive in 98d654f (the static-render process is throwaway; subscribing it is wasted work).

Test note

The existing "listens for job:state change events" test only passed by accident: it asserted the test process received the broadcast, and the test process was only subscribed because the unconditional subscribe ran during the static-render pass (which executes in the test process). It now asserts the actual behavior — the view re-renders with new jobs after a broadcast.

Testing

  • 3 new throttle unit tests (broadcast after interval, burst coalescing, re-arm after flush)
  • tooling/lint_test.sh green

Every Oban job start/stop/exception broadcast "job:state" immediately, and
each broadcast makes every subscribed dashboard LiveView re-run its counts
and paginated queries. With a busy download queue, an open dashboard
hammered SQLite with redundant reads.

Job state telemetry now routes through a small coalescing GenServer that
broadcasts at most once per second (trailing edge, so the final state of a
burst is always reflected).

Also guard the JobTableLive subscription with connected?/1, matching
HistoryTableLive, so the throwaway static-render process doesn't subscribe.
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

🐳 Image for commit fae3b6c published: ghcr.io/communitymaintained/pinchflat-dev:pr-137-fae3b6c

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.

1 participant