From 35313c57d44cd79a388b2ffa7f28872b2aa9c71e Mon Sep 17 00:00:00 2001 From: you Date: Sat, 21 Mar 2026 07:15:22 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20revert=20broken=20SQL=20region=20filteri?= =?UTF-8?q?ng=20for=20nodes=20=E2=80=94=20use=20in-memory=20index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The subagent used a non-existent column (sender_key) in the SQL join. Reverted to the same byObserver + _nodeHashIndex approach used by bulk-health and network-status endpoints. --- server.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/server.js b/server.js index 0dd5b79..93fb5f6 100644 --- a/server.js +++ b/server.js @@ -1040,13 +1040,19 @@ app.get('/api/nodes', (req, res) => { const regionObsIds = getObserverIdsForRegions(region); let regionNodeKeys = null; if (regionObsIds && regionObsIds.size > 0) { - // Use SQL to find all node pubkeys observed by regional observers - const obsArray = [...regionObsIds]; - const placeholders = obsArray.map(() => '?').join(','); - const rows = db.db.prepare( - `SELECT DISTINCT t.sender_key FROM observations o JOIN transmissions t ON o.hash = t.hash WHERE o.observer_id IN (${placeholders})` - ).all(...obsArray); - regionNodeKeys = new Set(rows.map(r => r.sender_key)); + // Collect all packet hashes seen by regional observers + const regionalHashes = new Set(); + for (const obsId of regionObsIds) { + const obs = pktStore.byObserver.get(obsId); + if (obs) for (const o of obs) regionalHashes.add(o.hash); + } + // Find node pubkeys from those packets (via _nodeHashIndex) + regionNodeKeys = new Set(); + for (const [pubkey, hashes] of pktStore._nodeHashIndex) { + for (const h of hashes) { + if (regionalHashes.has(h)) { regionNodeKeys.add(pubkey); break; } + } + } } const clause = where.length ? 'WHERE ' + where.join(' AND ') : '';