mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-05-27 05:24:10 +00:00
fix: debounce server cache invalidation (5s window), fix client cache stat reporting
This commit is contained in:
+3
-2
@@ -66,8 +66,9 @@ window.apiPerf = function() {
|
||||
})).sort((a, b) => b.totalMs - a.totalMs);
|
||||
console.table(rows);
|
||||
const hitRate = _apiPerf.calls ? Math.round(_apiPerf.cacheHits / _apiPerf.calls * 100) : 0;
|
||||
console.log(`Cache: ${_apiPerf.cacheHits} hits / ${_apiPerf.calls} calls (${hitRate}% hit rate)`);
|
||||
return { calls: _apiPerf.calls, avgMs: Math.round(_apiPerf.totalMs / (_apiPerf.calls - _apiPerf.cacheHits || 1)), cacheHits: _apiPerf.cacheHits, hitRate: hitRate + '%', endpoints: rows };
|
||||
const misses = _apiPerf.calls - _apiPerf.cacheHits;
|
||||
console.log(`Cache: ${_apiPerf.cacheHits} hits / ${misses} misses (${hitRate}% hit rate)`);
|
||||
return { calls: _apiPerf.calls, avgMs: Math.round(_apiPerf.totalMs / (misses || 1)), cacheHits: _apiPerf.cacheHits, cacheMisses: misses, cacheHitRate: hitRate, endpoints: rows };
|
||||
};
|
||||
|
||||
function timeAgo(iso) {
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@
|
||||
<main id="app" role="main"></main>
|
||||
|
||||
<script src="vendor/qrcode.js"></script>
|
||||
<script src="app.js?v=1773972187"></script>
|
||||
<script src="app.js?v=1773972918"></script>
|
||||
<script src="home.js?v=1773972187"></script>
|
||||
<script src="packets.js?v=1773972187"></script>
|
||||
<script src="map.js?v=1773972187" onerror="console.error('Failed to load:', this.src)"></script>
|
||||
|
||||
@@ -46,6 +46,19 @@ class TTLCache {
|
||||
if (key.startsWith(prefix)) this.store.delete(key);
|
||||
}
|
||||
}
|
||||
// Debounced invalidation — wait for burst of packets to settle
|
||||
debouncedInvalidateAll() {
|
||||
if (this._debounceTimer) return; // already scheduled
|
||||
this._debounceTimer = setTimeout(() => {
|
||||
this._debounceTimer = null;
|
||||
this.invalidate('analytics:');
|
||||
this.invalidate('channels');
|
||||
this.invalidate('node:');
|
||||
this.invalidate('health:');
|
||||
this.invalidate('observers');
|
||||
this.invalidate('bulk-health');
|
||||
}, 5000); // batch invalidations over 5s window
|
||||
}
|
||||
clear() { this.store.clear(); }
|
||||
get size() { return this.store.size; }
|
||||
}
|
||||
@@ -290,12 +303,7 @@ try {
|
||||
|
||||
|
||||
// Invalidate caches on new data
|
||||
cache.invalidate('analytics:');
|
||||
cache.invalidate('channels');
|
||||
cache.invalidate('node:');
|
||||
cache.invalidate('health:');
|
||||
cache.invalidate('observers');
|
||||
cache.invalidate('bulk-health');
|
||||
cache.debouncedInvalidateAll();
|
||||
|
||||
const broadcastData = { id: packetId, raw: msg.raw, decoded, snr: msg.SNR, rssi: msg.RSSI, hash: msg.hash, observer: observerId };
|
||||
broadcast({ type: 'packet', data: broadcastData });
|
||||
@@ -634,12 +642,7 @@ app.post('/api/packets', (req, res) => {
|
||||
|
||||
|
||||
// Invalidate caches on new data
|
||||
cache.invalidate('analytics:');
|
||||
cache.invalidate('channels');
|
||||
cache.invalidate('node:');
|
||||
cache.invalidate('health:');
|
||||
cache.invalidate('observers');
|
||||
cache.invalidate('bulk-health');
|
||||
cache.debouncedInvalidateAll();
|
||||
|
||||
broadcast({ type: 'packet', data: { id: packetId, decoded } });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user