opencode-statboard 2.10.22 → 2.10.24
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 +2 -2
- package/package.json +1 -1
- package/public/index.html +4 -1
- package/server.js +25 -12
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 || '
|
|
8
|
-
const ITHROTTLE_DELAY_MS = parseInt(process.env.OPENCODE_ITHROTTLE_DELAY_MS || '
|
|
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
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
|
-
|
|
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
|
|
24
|
-
//
|
|
25
|
-
|
|
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
|
|
@@ -277,8 +278,8 @@ function refreshTrend(days) {
|
|
|
277
278
|
return { trend: hit ? Object.assign({}, hit, { stale: true }) : null, pending };
|
|
278
279
|
}
|
|
279
280
|
|
|
280
|
-
function localDayKey(d) { return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`; }
|
|
281
|
-
function dateOfKey(k) { const [y, m, d] = k.split('-').map(Number); return new Date(y, m, d); }
|
|
281
|
+
function localDayKey(d) { const p = (n) => String(n).padStart(2, '0'); return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`; }
|
|
282
|
+
function dateOfKey(k) { const [y, m, d] = k.split('-').map(Number); return new Date(y, m - 1, d); }
|
|
282
283
|
function modelNameOf(provider, model) { return `${provider || 'unknown'}/${model || 'unknown'}`; }
|
|
283
284
|
function splitModelName(name) {
|
|
284
285
|
const i = String(name).indexOf('/');
|
|
@@ -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
|
-
//
|
|
352
|
-
|
|
353
|
-
|
|
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,11 +867,21 @@ 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.
|
|
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.
|
|
867
874
|
setImmediate(() => {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
if (
|
|
871
|
-
|
|
875
|
+
const scopes = [1, 7, 30, -1];
|
|
876
|
+
const warm = (i) => {
|
|
877
|
+
if (i >= scopes.length) return;
|
|
878
|
+
try {
|
|
879
|
+
const r = buildReportFromDb(scopes[i]);
|
|
880
|
+
if (r && r.stats && r.stats.ok) reportCache[String(scopes[i])] = r;
|
|
881
|
+
} catch (_) {}
|
|
882
|
+
setImmediate(() => warm(i + 1));
|
|
883
|
+
};
|
|
884
|
+
warm(0);
|
|
872
885
|
});
|
|
873
886
|
}
|
|
874
887
|
|