feat(dashboard): poll optimisation — T4, T5, T6

T4: workstreams.md and dependencies.md now call /state/deps instead of the
    full /state/summary — removes 2 heavy 10-table queries per 60 s cycle.

T5: index.md's 4 independent polling loops (summaryState, sbomSnapState,
    regsState, wsChartState) consolidated into a single pageState generator
    with one Promise.all batch and a shared backoff counter.

T6: config.js gains waitForVisible(ms) — pauses polling entirely while the
    tab is hidden and fires immediately on visibilitychange.  pollDelay()
    simplified (hidden-tab POLL_HIDDEN logic removed).  All 16 polling pages
    migrated from await sleep(pollDelay(...)) to await waitForVisible(pollDelay(...)).

CUST-WP-0039 complete — all 6 tasks done.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-11 17:58:18 +02:00
parent b832032cc3
commit 90c5ea50f7
18 changed files with 111 additions and 155 deletions

View File

@@ -1,19 +1,30 @@
export const API = "http://127.0.0.1:8000";
export const POLL = 15_000;
export const POLL_HEAVY = 60_000;
export const POLL_HIDDEN = 120_000;
export const FETCH_TIMEOUT = 12_000;
export function pollDelay({ok = true, base = POLL, failures = 0} = {}) {
const hidden = typeof document !== "undefined" && document.visibilityState === "hidden";
const failureDelay = ok ? base : Math.min(base * 2 ** Math.min(failures, 4), 300_000);
return hidden ? Math.max(failureDelay, POLL_HIDDEN) : failureDelay;
return ok ? base : Math.min(base * 2 ** Math.min(failures, 4), 300_000);
}
export function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Waits `ms` if the tab is visible; pauses until the tab becomes visible if hidden,
// then returns immediately so the next poll fires as soon as the user returns.
export async function waitForVisible(ms) {
if (typeof document === "undefined") return sleep(ms);
if (document.visibilityState === "visible") return sleep(ms);
return new Promise(resolve => {
const handler = () => {
document.removeEventListener("visibilitychange", handler);
resolve();
};
document.addEventListener("visibilitychange", handler);
});
}
export async function apiFetch(path, options = {}) {
const url = path.startsWith("http") ? path : `${API}${path}`;
const timeout = options.timeout ?? FETCH_TIMEOUT;