Browse Source

fix(panel): refresh memory stats periodically

Previously __refreshStats() ran once at panel init. If the bridge was still starting (supervisor 5s delay), fetchBridge failed and the status line stayed stuck at WS: ? entries: 0 (always 0) until F5. Now: setInterval(__refreshStats, 30000) plus refresh after every successful health probe.
master
Serge Shutov 1 week ago
parent
commit
e94d7a2e81
  1. 9
      content/content.js

9
content/content.js

@ -365,9 +365,16 @@ if (parsed.calls.length === 0) { if (hasMarker) { try { var __dh = hashText(text @@ -365,9 +365,16 @@ if (parsed.calls.length === 0) { if (hasMarker) { try { var __dh = hashText(text
canStart = true;
});
setInterval(function () {
BRIDGE.health().then(function (r) { if (UI && UI.setConnected) UI.setConnected(!!(r && r.ok)); });
BRIDGE.health().then(function (r) {
if (UI && UI.setConnected) UI.setConnected(!!(r && r.ok));
if (r && r.ok) __refreshStats();
});
}, 30000);
__refreshStats();
// Keep stats fresh: without this, if bridge was down at init, the panel
// stays stuck at "? 0 (always 0)" until F5. Refresh every 30s, and also
// immediately on every successful health probe.
setInterval(__refreshStats, 30000);
});
});
function __refreshStats() { try { var DB = globalThis.DSH_BRIDGE; if (!UI || !UI.setStats) return; if (!DB || !DB.fetchBridge) { UI.setStats('?', 0, 0); return; } DB.fetchBridge('GET', '/memory/state').then(function (j) { var st = (j && j.ok && j.data) ? j.data : {}; var entries = st.entries || []; var total = entries.length; var alwaysN = entries.filter(function (e) { return e.importance === 'always' && e.state !== 'archive' && e.state !== 'done'; }).length; return DB.fetchBridge('GET', '/health').then(function (hj) { UI.setStats((hj && hj.ok && hj.workspace) || '?', total, alwaysN); }); }).catch(function (e) { console.warn('[dsh-memory] stats ' + String(e)); UI.setStats('?', 0, 0); }); } catch (e) { console.warn('[dsh-memory] stats ' + String(e)); } }

Loading…
Cancel
Save