From f8638974c7ff13146d09052a326bb47160778dca Mon Sep 17 00:00:00 2001 From: you Date: Fri, 20 Mar 2026 03:48:55 +0000 Subject: [PATCH] =?UTF-8?q?perf:=20smart=20cache=20invalidation=20?= =?UTF-8?q?=E2=80=94=20only=20channels/observers=20on=20packet=20burst,=20?= =?UTF-8?q?node/health/analytics=20expire=20by=20TTL,=20node=20invalidated?= =?UTF-8?q?=20on=20ADVERT=20only?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server.js b/server.js index 883692bd..c080e5a7 100644 --- a/server.js +++ b/server.js @@ -75,12 +75,10 @@ class TTLCache { if (this._debounceTimer) return; 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'); + // Only invalidate truly time-sensitive caches + this.invalidate('channels'); // chat messages need freshness + this.invalidate('observers'); // observer packet counts + // node:, health:, bulk-health, analytics: all have long TTLs — let them expire naturally }, TTL.invalidationDebounce); } clear() { this.store.clear(); } @@ -325,6 +323,10 @@ try { const p = decoded.payload; const role = p.flags ? (p.flags.repeater ? 'repeater' : p.flags.room ? 'room' : p.flags.sensor ? 'sensor' : 'companion') : 'companion'; db.upsertNode({ public_key: p.pubKey, name: p.name || null, role, lat: p.lat, lon: p.lon, last_seen: now }); + // Invalidate this node's caches on advert + cache.invalidate('node:' + p.pubKey); + cache.invalidate('health:' + p.pubKey); + cache.invalidate('bulk-health'); } if (observerId) {