opencode-statboard 2.9.1 → 2.9.2
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/package.json +1 -1
- package/server.js +20 -3
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -20,9 +20,13 @@ const TREND_MS = 60 * 1000;
|
|
|
20
20
|
const REPORT_TTL = 10 * 60 * 1000;
|
|
21
21
|
const TOOLS_TTL = 5 * 60 * 1000;
|
|
22
22
|
const STATS_TTL = 10 * 60 * 1000;
|
|
23
|
-
|
|
23
|
+
// Backup interval: default 1 hour (was 5 min — far too aggressive for 3GB DB).
|
|
24
|
+
// Configurable via OPENCODE_BACKUP_INTERVAL_MS env var.
|
|
25
|
+
const CACHE_CLEANUP_MS = parseInt(process.env.OPENCODE_BACKUP_INTERVAL_MS || String(60 * 60 * 1000), 10);
|
|
24
26
|
const BACKUP_DIR = path.join(__dirname, 'backups');
|
|
25
27
|
const BACKUP_RETENTION = parseInt(process.env.OPENCODE_BACKUP_RETENTION || '3', 10) || 3;
|
|
28
|
+
// Set OPENCODE_BACKUP_INTERVAL_MS=0 to disable auto backup entirely
|
|
29
|
+
const BACKUP_DISABLED = process.env.OPENCODE_BACKUP_INTERVAL_MS === '0';
|
|
26
30
|
const BACKUP_SRC = process.env.OPENCODE_DATA
|
|
27
31
|
? path.join(process.env.OPENCODE_DATA, 'opencode.db')
|
|
28
32
|
: path.join(process.env.USERPROFILE || process.env.HOME || '', '.local', 'share', 'opencode', 'opencode.db');
|
|
@@ -336,6 +340,11 @@ function marketOf(tok, provider, model) {
|
|
|
336
340
|
// message count, output, reasoning, active ms, wall span on the MESSAGE clock)
|
|
337
341
|
// and msgAgentAgg, so reports need no extra queries.
|
|
338
342
|
const ATTR_TTL = 300000;
|
|
343
|
+
// Minimum interval between full scans, regardless of DB revision changes.
|
|
344
|
+
// Prevents excessive scanning when opencode is actively writing (WAL checkpoints
|
|
345
|
+
// change DB mtime/size constantly, making revision appear changed every time).
|
|
346
|
+
// Default 15 minutes — configurable via OPENCODE_MIN_SCAN_INTERVAL_MS.
|
|
347
|
+
const MIN_SCAN_INTERVAL = parseInt(process.env.OPENCODE_MIN_SCAN_INTERVAL_MS || String(15 * 60 * 1000), 10);
|
|
339
348
|
// Tool counts change slowly but the embedded-content scan costs ~2.8s on a
|
|
340
349
|
// 2.7GB live DB, so it is computed by the stats WORKER (see spawnAttrWorker)
|
|
341
350
|
// and only ever READ here. `fromWorker` marks worker-supplied data, which is
|
|
@@ -562,6 +571,9 @@ async function attributeUsage(startMs, endMs, periodStartsMs) {
|
|
|
562
571
|
let attrAllCache = null;
|
|
563
572
|
let attrBundlePending = false;
|
|
564
573
|
let attrLastSave = 0;
|
|
574
|
+
let attrLastScan = 0; // timestamp of last scan start
|
|
575
|
+
// Set OPENCODE_ATTR_SCAN_DISABLED=1 to disable background attr scans entirely
|
|
576
|
+
const ATTR_SCAN_DISABLED = process.env.OPENCODE_ATTR_SCAN_DISABLED === '1';
|
|
565
577
|
const EMPTY_ATTR = {
|
|
566
578
|
perDay: {}, perModel: {}, perAgent: {}, perSession: {},
|
|
567
579
|
totals: { sessions: 0, messages: 0, input: 0, output: 0, reasoning: 0, cacheRead: 0, cacheWrite: 0, cost: 0 },
|
|
@@ -722,16 +734,21 @@ function refreshAttrBundle() {
|
|
|
722
734
|
if (attrBundlePending) return attrAllCache ? attrAllCache.a : null;
|
|
723
735
|
const now = Date.now();
|
|
724
736
|
if (attrAllCache && now - attrAllCache.at < ATTR_TTL) return attrAllCache.a;
|
|
737
|
+
// Enforce minimum scan interval to prevent excessive scanning when DB
|
|
738
|
+
// revision changes frequently (e.g., due to WAL checkpoints during active
|
|
739
|
+
// opencode usage). This is independent of TTL and revision checks.
|
|
740
|
+
if (attrLastScan && now - attrLastScan < MIN_SCAN_INTERVAL) {
|
|
741
|
+
return attrAllCache ? attrAllCache.a : null;
|
|
742
|
+
}
|
|
725
743
|
const rev = dbRevision();
|
|
726
744
|
// DB hasn't changed since the last scan: just extend the TTL, no scan.
|
|
727
|
-
// This is the common case on a machine where opencode is idle (which is most
|
|
728
|
-
// of the time), and it turns a 30-60s rebuild into a stat() call.
|
|
729
745
|
if (attrAllCache && rev && attrAllCache.dbRevision === rev) {
|
|
730
746
|
attrAllCache.at = now;
|
|
731
747
|
return attrAllCache.a;
|
|
732
748
|
}
|
|
733
749
|
attrBundlePending = true;
|
|
734
750
|
attrWorkerActive = true;
|
|
751
|
+
attrLastScan = now;
|
|
735
752
|
spawnAttrWorker(now, rev);
|
|
736
753
|
return attrAllCache ? attrAllCache.a : null;
|
|
737
754
|
}
|