opencode-statboard 2.8.4 → 2.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/attr-worker.js +1 -0
- package/package.json +1 -1
- package/server.js +25 -5
package/attr-worker.js
CHANGED
|
@@ -18,6 +18,7 @@ const srv = require('./server.js');
|
|
|
18
18
|
parentPort.postMessage({
|
|
19
19
|
ok: true,
|
|
20
20
|
builtAt: now,
|
|
21
|
+
dbRevision: srv.dbRevision(),
|
|
21
22
|
json: srv.serializeBundle(bundle, { embedded: srv.getEmbeddedToolsFlag(), startMs: workerData.toolsStartMs || 0, counts }),
|
|
22
23
|
tools: { embedded: srv.getEmbeddedToolsFlag(), startMs: workerData.toolsStartMs || 0, counts },
|
|
23
24
|
});
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -602,6 +602,16 @@ const BUNDLE_SAVE_MS = 60000; // don't hammer the disk while chatting
|
|
|
602
602
|
function dbFingerprint() {
|
|
603
603
|
return BACKUP_SRC;
|
|
604
604
|
}
|
|
605
|
+
// Cheap revision check for the REBUILD decision (distinct from the cache
|
|
606
|
+
// fingerprint above, which is intentionally path-only). Two servers pointed at
|
|
607
|
+
// the same DB see the same revision, so a DB that has not changed since the
|
|
608
|
+
// last scan is never scanned again.
|
|
609
|
+
function dbRevision() {
|
|
610
|
+
try {
|
|
611
|
+
const st = fs.statSync(BACKUP_SRC);
|
|
612
|
+
return `${BACKUP_SRC}|${st.size}|${Math.round(st.mtimeMs)}`;
|
|
613
|
+
} catch (_) { return BACKUP_SRC; }
|
|
614
|
+
}
|
|
605
615
|
function serializeBundle(a, tools) {
|
|
606
616
|
// MUST NOT mutate: the caller serializes the LIVE bundle, and swapping a
|
|
607
617
|
// bucket's `sessions` Set for an array in place would break every later
|
|
@@ -623,7 +633,7 @@ function serializeBundle(a, tools) {
|
|
|
623
633
|
perAgentPeriod: setToArr(sl.perAgentPeriod),
|
|
624
634
|
};
|
|
625
635
|
return JSON.stringify({
|
|
626
|
-
v: 2, builtAt: a.builtAt, db: dbFingerprint(), byPeriodStart: a.byPeriodStart,
|
|
636
|
+
v: 2, builtAt: a.builtAt, db: dbFingerprint(), dbRevision: dbRevision(), byPeriodStart: a.byPeriodStart,
|
|
627
637
|
tools: tools ? { embedded: tools.embedded, startMs: tools.startMs, counts: tools.counts } : null,
|
|
628
638
|
perDay: days,
|
|
629
639
|
perModel: setToArr(a.perModel), perAgent: setToArr(a.perAgent),
|
|
@@ -711,9 +721,17 @@ function refreshAttrBundle() {
|
|
|
711
721
|
if (attrBundlePending) return attrAllCache ? attrAllCache.a : null;
|
|
712
722
|
const now = Date.now();
|
|
713
723
|
if (attrAllCache && now - attrAllCache.at < ATTR_TTL) return attrAllCache.a;
|
|
724
|
+
const rev = dbRevision();
|
|
725
|
+
// DB hasn't changed since the last scan: just extend the TTL, no scan.
|
|
726
|
+
// This is the common case on a machine where opencode is idle (which is most
|
|
727
|
+
// of the time), and it turns a 30-60s rebuild into a stat() call.
|
|
728
|
+
if (attrAllCache && rev && attrAllCache.dbRevision === rev) {
|
|
729
|
+
attrAllCache.at = now;
|
|
730
|
+
return attrAllCache.a;
|
|
731
|
+
}
|
|
714
732
|
attrBundlePending = true;
|
|
715
733
|
attrWorkerActive = true;
|
|
716
|
-
spawnAttrWorker(now);
|
|
734
|
+
spawnAttrWorker(now, rev);
|
|
717
735
|
return attrAllCache ? attrAllCache.a : null;
|
|
718
736
|
}
|
|
719
737
|
|
|
@@ -728,7 +746,7 @@ function waitForBundle(timeoutMs) {
|
|
|
728
746
|
});
|
|
729
747
|
}
|
|
730
748
|
|
|
731
|
-
function spawnAttrWorker(now) {
|
|
749
|
+
function spawnAttrWorker(now, rev) {
|
|
732
750
|
// Failure path: unblock waiters and, on a truly cold start, build inline so
|
|
733
751
|
// the dashboard still shows numbers.
|
|
734
752
|
function failBundle(msg) {
|
|
@@ -748,7 +766,7 @@ function spawnAttrWorker(now) {
|
|
|
748
766
|
}
|
|
749
767
|
let w;
|
|
750
768
|
try {
|
|
751
|
-
w = new Worker(ATTR_WORKER, { workerData: { now, toolsStartMs: 0 } });
|
|
769
|
+
w = new Worker(ATTR_WORKER, { workerData: { now, toolsStartMs: 0, dbRevision: rev } });
|
|
752
770
|
} catch (e) {
|
|
753
771
|
// Worker unavailable (very old Node / restricted env): build inline.
|
|
754
772
|
console.error('attr worker spawn failed, building inline:', e.message);
|
|
@@ -764,7 +782,8 @@ function spawnAttrWorker(now) {
|
|
|
764
782
|
try {
|
|
765
783
|
const a = reviveBundle(JSON.parse(m.json));
|
|
766
784
|
a.builtAt = m.builtAt;
|
|
767
|
-
|
|
785
|
+
a.dbRevision = m.dbRevision || rev;
|
|
786
|
+
attrAllCache = { at: m.builtAt, a, dbRevision: a.dbRevision };
|
|
768
787
|
if (m.tools) {
|
|
769
788
|
toolsCache = { at: m.builtAt, embedded: m.tools.embedded, startMs: 0, counts: m.tools.counts, fromWorker: true };
|
|
770
789
|
}
|
|
@@ -1448,6 +1467,7 @@ if (require.main !== module) {
|
|
|
1448
1467
|
serializeBundle,
|
|
1449
1468
|
reviveBundle,
|
|
1450
1469
|
scanToolCounts,
|
|
1470
|
+
dbRevision,
|
|
1451
1471
|
getEmbeddedToolsFlag: () => schema.embeddedTools,
|
|
1452
1472
|
};
|
|
1453
1473
|
return;
|