Skip to content

Improve: spread widget polling so widgets do not fetch in lockstep - #53

Merged
SandObserver merged 1 commit into
mainfrom
perf/widget-poll-jitter
Aug 12, 2026
Merged

SandObserver merged 1 commit into
mainfrom
perf/widget-poll-jitter

Conversation

@SandObserver

Copy link
Copy Markdown
Owner

Summary

  • Add ui/js/jitter.js, holding the ±15% spread as one dependency-free helper, and register both path forms in tsconfig.frontend.json.
  • Use it for the repeat interval in the widget toolbox's poll(), leaving the first fetch immediate.
  • Replace the dashboard shell's local _jit with the shared helper, so the rule has one definition.
  • Return 0 for an interval that is missing, negative or not a number, so a caller cannot schedule a NaN delay that setTimeout turns into a busy loop.
  • Document the behaviour on poll() in docs/widgets.md.

Testing
All green, apart from the Docker build smoke test, which needs a local Docker daemon. Added 5 tests: the jitter bounds under stubbed randomness and across 500 draws, unusable intervals, and a poll test that captures the scheduled delay to confirm the repeat is spread while the first fetch waits for nothing.

Checklist

  • Stays within the project constraints: one container, no runtime dependencies, no build step (see CONTRIBUTING.md).
  • Tests added or updated for new logic, and the full suite, lint, and typechecks pass.
  • Docs updated if behavior or configuration changed.
  • CHANGELOG.md updated under Unreleased if the change is user-visible.

The widget toolbox scheduled each repeat on an exact interval, so
widgets opened together kept fetching on the same tick. The dashboard
shell had solved this for its own polls with a local helper.

Move that helper into ui/js/jitter.js and use it in both. The first
fetch stays immediate: that one is the widget's content.
@SandObserver SandObserver added the javascript Pull requests that update javascript code label Aug 12, 2026
@SandObserver
SandObserver merged commit db438d6 into main Aug 12, 2026
4 checks passed
@SandObserver
SandObserver deleted the perf/widget-poll-jitter branch August 12, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Pull requests that update javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant