dashboard: cut page sync latency to ~scan-time + ≤5 s
Three display-side fixes, no signal-logic changes: - run_cycle publishes snapshot.json BEFORE the news refresh — news I/O (FF + 4 RSS + possible DeepSeek calls) took 20-30 s on TTL-expired cycles and kept fresh signals off the page (publish_all split into publish_snapshot/publish_news, kept for boot) - page polls every 5 s (was 20 s) using conditional GETs: dropped the ?t= cache-buster + no-store so Apache answers unchanged files with bodyless 304s - boundary refetch sniper re-armed: fires 2 s after next_scan_epoch regardless of distance (the old delay<POLL_MS guard would have been dead code at 5 s polling) New Module 20 test locks the snapshot-before-news ordering. 352 tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017mbXs9HRawZhD1uZ3ze7zQ
This commit is contained in:
+12
-5
@@ -400,7 +400,9 @@ const IND_SHORT = {ema_trend:"EMA", rsi:"RSI", macd:"MACD", bollinger:"BB",
|
||||
const ARROW = {STRONG_BUY:"⇈", BUY:"↑", NEUTRAL:"→", SELL:"↓", STRONG_SELL:"⇊"};
|
||||
const TF_LABEL = {"5min":"M5", "15min":"M15", "1h":"H1", "4h":"H4"};
|
||||
const TF_ORDER = ["5min","15min","1h","4h"];
|
||||
const POLL_MS = 20000;
|
||||
/* 5 s polling is cheap because fetchJSON uses conditional GETs — Apache
|
||||
answers unchanged files with 304, so most polls transfer no body. */
|
||||
const POLL_MS = 5000;
|
||||
|
||||
let snapshot = null, news = null;
|
||||
let clockOffset = 0; // serverEpoch - localEpoch
|
||||
@@ -699,7 +701,10 @@ function renderWire() {
|
||||
|
||||
/* ── polling ──────────────────────────────────────────────────── */
|
||||
async function fetchJSON(name) {
|
||||
const res = await fetch(`${name}?t=${Date.now()}`, {cache: "no-store"});
|
||||
/* no-cache = revalidate with the server every time (If-Modified-Since);
|
||||
unchanged files come back 304 with no body, so aggressive polling
|
||||
stays nearly free. The old ?t= cache-buster forced full downloads. */
|
||||
const res = await fetch(name, {cache: "no-cache"});
|
||||
if (!res.ok) throw new Error(`${name}: HTTP ${res.status}`);
|
||||
/* The Date header is stamped at RESPONSE time — snapshot.server_time_epoch
|
||||
is stamped at publish time, minutes stale between candle closes. */
|
||||
@@ -724,13 +729,15 @@ async function poll() {
|
||||
tick(); // countdowns appear immediately, not after the first 1 s tick
|
||||
|
||||
/* one-shot refetch shortly after the next expected publish, so a
|
||||
fresh scan appears within seconds of the candle close */
|
||||
fast scan appears ~2 s after the publisher wakes instead of
|
||||
waiting out the poll interval (the regular POLL_MS loop covers
|
||||
slower scans) */
|
||||
const nextScan = Math.min(...TF_ORDER.map(tf =>
|
||||
snapshot.timeframes[tf]?.next_scan_epoch || Infinity));
|
||||
if (isFinite(nextScan)) {
|
||||
clearTimeout(refetchTimer);
|
||||
const delay = (nextScan - nowServer() + 6) * 1000;
|
||||
if (delay > 0 && delay < POLL_MS) refetchTimer = setTimeout(poll, delay);
|
||||
const delay = (nextScan - nowServer() + 2) * 1000;
|
||||
if (delay > 0) refetchTimer = setTimeout(poll, delay);
|
||||
}
|
||||
} catch (err) {
|
||||
const last = lastPollOk ? ` Last update ${lastPollOk.toLocaleTimeString()}.` : "";
|
||||
|
||||
Reference in New Issue
Block a user