opencode-statboard 2.10.23 → 2.10.25

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 CHANGED
@@ -4,8 +4,8 @@ if (workerData && workerData.dbPath && !process.env.OPENCODE_DATA) {
4
4
  }
5
5
  const srv = require('./server.js');
6
6
 
7
- const ITHROTTLE_BATCH = parseInt(process.env.OPENCODE_ITHROTTLE_BATCH || '1000', 10);
8
- const ITHROTTLE_DELAY_MS = parseInt(process.env.OPENCODE_ITHROTTLE_DELAY_MS || '5', 10);
7
+ const ITHROTTLE_BATCH = parseInt(process.env.OPENCODE_ITHROTTLE_BATCH || '300', 10);
8
+ const ITHROTTLE_DELAY_MS = parseInt(process.env.OPENCODE_ITHROTTLE_DELAY_MS || '15', 10);
9
9
 
10
10
  function throttle(iteration) {
11
11
  if (iteration % ITHROTTLE_BATCH === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-statboard",
3
- "version": "2.10.23",
3
+ "version": "2.10.25",
4
4
  "description": "Real-time dashboard for opencode token usage and cost statistics",
5
5
  "main": "server.js",
6
6
  "bin": {
package/public/index.html CHANGED
@@ -1055,7 +1055,10 @@ async function loadReport(days) {
1055
1055
  const j = await r.json();
1056
1056
  if (j.ok === false) { $('rawText').textContent = t('reportFail'); return null; }
1057
1057
  if (!j.ready || !j.report) {
1058
- $('rawText').textContent = '⏳ ' + t('generating') + '…';
1058
+ // Never blank a report the user is already reading: keep the current
1059
+ // render and only hint that a refresh is in flight. The spinner text is
1060
+ // for the very first load, when there is nothing to keep.
1061
+ if (!window.__lastReport) $('rawText').textContent = '⏳ ' + t('generating') + '…';
1059
1062
  reportRetry++;
1060
1063
  if (reportRetry < MAX_REPORT_RETRIES) {
1061
1064
  const delay = Math.min(1000 * Math.pow(1.5, reportRetry), 15000);
package/server.js CHANGED
@@ -20,9 +20,10 @@ 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
- // 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);
23
+ // Backup interval: default 6 hours. Copying + gzipping a 2.8GB DB is heavy
24
+ // disk work; doing it hourly made the whole machine stutter.
25
+ // Configurable via OPENCODE_BACKUP_INTERVAL_MS env var; 0 disables auto backup.
26
+ const CACHE_CLEANUP_MS = parseInt(process.env.OPENCODE_BACKUP_INTERVAL_MS || String(6 * 60 * 60 * 1000), 10);
26
27
  const BACKUP_DIR = path.join(__dirname, 'backups');
27
28
  const BACKUP_RETENTION = parseInt(process.env.OPENCODE_BACKUP_RETENTION || '3', 10) || 3;
28
29
  // Set OPENCODE_BACKUP_INTERVAL_MS=0 to disable auto backup entirely
@@ -348,9 +349,11 @@ const ATTR_TTL = 300000;
348
349
  const MIN_SCAN_INTERVAL = parseInt(process.env.OPENCODE_MIN_SCAN_INTERVAL_MS || String(30 * 60 * 1000), 10);
349
350
 
350
351
  // I/O throttling for the attr worker: process N rows, then yield for M ms.
351
- // Prevents the worker from saturating the disk. Configurable via env vars.
352
- const ITHROTTLE_BATCH = parseInt(process.env.OPENCODE_ITHROTTLE_BATCH || '1000', 10); // rows per yield
353
- const ITHROTTLE_DELAY_MS = parseInt(process.env.OPENCODE_ITHROTTLE_DELAY_MS || '5', 10); // ms to sleep
352
+ // Defaults are deliberately gentle: a 3GB DB scanned at 1000 rows/5ms saturated
353
+ // the physical disk and made other programs stutter. 300 rows/15ms is slower
354
+ // overall but stays well under the disk's attention.
355
+ const ITHROTTLE_BATCH = parseInt(process.env.OPENCODE_ITHROTTLE_BATCH || '300', 10); // rows per yield
356
+ const ITHROTTLE_DELAY_MS = parseInt(process.env.OPENCODE_ITHROTTLE_DELAY_MS || '15', 10); // ms to sleep
354
357
  // Tool counts change slowly but the embedded-content scan costs ~2.8s on a
355
358
  // 2.7GB live DB, so it is computed by the stats WORKER (see spawnAttrWorker)
356
359
  // and only ever READ here. `fromWorker` marks worker-supplied data, which is
@@ -864,12 +867,11 @@ function settleBundle(now, msg) {
864
867
  if (typeof refresh === 'function') Promise.resolve(refresh()).catch(() => {});
865
868
  // The default scope is the first thing on screen: build it the moment the
866
869
  // bundle lands so the opening view never shows a "generating" spinner.
867
- setImmediate(() => {
868
- try {
869
- const r = buildReportFromDb(1);
870
- if (r && r.stats && r.stats.ok) reportCache['1'] = r;
871
- } catch (_) {}
872
- });
870
+ // Prewarm EVERY scope the global switch can show, so the first click on
871
+ // Today/7 days/Month/All is an in-memory swap (1–2ms) instead of a build.
872
+ // Each build is ~25ms of pure in-memory work (no DB hit), and they run one
873
+ // per tick so startup never blocks.
874
+ prewarmReports();
873
875
  }
874
876
 
875
877
  // Pure tool-count scan (no cache side effects) so the worker can run it.
@@ -1355,6 +1357,21 @@ function buildReportFromDb(days) {
1355
1357
  };
1356
1358
  }
1357
1359
 
1360
+ function prewarmReports() {
1361
+ setImmediate(() => {
1362
+ const scopes = [1, 7, 30, -1];
1363
+ const warm = (i) => {
1364
+ if (i >= scopes.length) return;
1365
+ try {
1366
+ const r = buildReportFromDb(scopes[i]);
1367
+ if (r && r.stats && r.stats.ok) reportCache[String(scopes[i])] = r;
1368
+ } catch (_) {}
1369
+ setImmediate(() => warm(i + 1));
1370
+ };
1371
+ warm(0);
1372
+ });
1373
+ }
1374
+
1358
1375
  function refreshReport(days) {
1359
1376
  const key = String(days);
1360
1377
  const hit = reportCache[key];
@@ -1574,6 +1591,9 @@ async function startServer() {
1574
1591
  const cached = loadBundleCache();
1575
1592
  attrAllCache = cached || null;
1576
1593
  getDb(); // detect schema now, so the worker result lands on a warm handle
1594
+ // Reports for every scope are pure in-memory builds off the bundle: do them
1595
+ // now so the first scope click is a swap, not a build.
1596
+ prewarmReports();
1577
1597
  // Spawn the fresh scan BEFORE the first refresh: while it is in flight the
1578
1598
  // request thread never runs the inline tool scan (toolCountsFor skips it).
1579
1599
  refreshAttrBundle();