mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-04-26 15:57:22 +00:00
fix: revert broken SQL region filtering for nodes — use in-memory index
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.
This commit is contained in:
20
server.js
20
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 ') : '';
|
||||
|
||||
Reference in New Issue
Block a user