From f2d7dabbb25f953dee51177537551e1d5bb6dbe0 Mon Sep 17 00:00:00 2001 From: you Date: Fri, 20 Mar 2026 02:24:46 +0000 Subject: [PATCH] perf: bump analytics cache to 5min, subpaths to 10min, cache subpath-detail --- server.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server.js b/server.js index 37000f4d..eda7b344 100644 --- a/server.js +++ b/server.js @@ -880,7 +880,7 @@ app.get('/api/analytics/rf', (req, res) => { avgPacketSize: packetSizes.length ? Math.round(packetSizes.reduce((a, b) => a + b, 0) / packetSizes.length) : 0, packetsPerHour, payloadTypes, snrByType: snrByTypeArr, signalOverTime, scatterData, timeSpanHours }; - cache.set('analytics:rf', _rfResult, 60000); + cache.set('analytics:rf', _rfResult, 300000); res.json(_rfResult); }); @@ -1046,7 +1046,7 @@ app.get('/api/analytics/topology', (req, res) => { multiObsNodes, bestPathList }; - cache.set('analytics:topology', _topoResult, 60000); + cache.set('analytics:topology', _topoResult, 300000); res.json(_topoResult); }); @@ -1109,7 +1109,7 @@ app.get('/api/analytics/channels', (req, res) => { channelTimeline, msgLengths }; - cache.set('analytics:channels', _chanResult, 60000); + cache.set('analytics:channels', _chanResult, 300000); res.json(_chanResult); }); @@ -1201,7 +1201,7 @@ app.get('/api/analytics/hash-sizes', (req, res) => { topHops, multiByteNodes }; - cache.set('analytics:hash-sizes', _hsResult, 60000); + cache.set('analytics:hash-sizes', _hsResult, 300000); res.json(_hsResult); }); @@ -1574,12 +1574,14 @@ app.get('/api/analytics/subpaths', (req, res) => { .slice(0, limit); const _spResult = { subpaths: ranked, totalPaths }; - cache.set(_ck, _spResult, 60000); + cache.set(_ck, _spResult, 600000); res.json(_spResult); }); // Subpath detail — stats for a specific subpath (by raw hop prefixes) app.get('/api/analytics/subpath-detail', (req, res) => { + const _sdck = 'analytics:subpath-detail:' + (req.query.hops || ''); + const _sdc = cache.get(_sdck); if (_sdc) return res.json(_sdc); const rawHops = (req.query.hops || '').split(',').filter(Boolean); if (rawHops.length < 2) return res.json({ error: 'Need at least 2 hops' }); @@ -1639,7 +1641,7 @@ app.get('/api/analytics/subpath-detail', (req, res) => { .slice(0, 10) .map(([name, count]) => ({ name, count })); - res.json({ + const _sdResult = { hops: rawHops, nodes, totalMatches: matching.length, @@ -1653,7 +1655,9 @@ app.get('/api/analytics/subpath-detail', (req, res) => { hourDistribution: hourBuckets, parentPaths: topParents, observers: topObservers - }); + }; + cache.set(_sdck, _sdResult, 600000); + res.json(_sdResult); }); // Static files + SPA fallback