Commit Graph

8 Commits

Author SHA1 Message Date
Kpa-clawbot
6dacdef6b8 perf: precompute subpath index at ingest time, fixes #168
The subpaths analytics endpoint iterated ALL packets on every cold query,
taking ~900ms.  The TTL cache only masked the problem.

Fix: maintain a precomputed raw-hop subpath index (map[string]int) that
is built once during Load() and incrementally updated during
IngestNewFromDB() and IngestNewObservations().

At query time the fast path iterates only unique raw subpaths (typically
a few thousand entries) instead of all packets (30K+), resolves hop
prefixes to names, and merges counts.  Region-filtered queries still
fall back to the O(N) path since they require per-transmission observer
checks.

Expected cold-hit improvement: ~900ms → <5ms for the common no-region
case.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-27 22:44:39 -07:00
Kpa-clawbot
f1cb840b5a fix: prepend to byPayloadType in IngestNewFromDB to preserve newest-first order
IngestNewFromDB was appending new transmissions to byPayloadType slices,
breaking the newest-first ordering established by Load(). This caused
GetChannelMessages (which iterates backwards assuming newest-first) to
place newly ingested messages at the wrong position, making them invisible
when returning the latest messages from the tail.

Changed append to prepend, matching the existing s.packets prepend pattern
on line 881. Added regression test.

fixes #198

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-27 21:56:54 -07:00
Kpa-clawbot
2435f2eaaf fix: observation timestamps, leaked fields, perf path normalization
- #178: Use strftime ISO 8601 format instead of datetime() for observation
  timestamps in all SQL queries (v3 + v2 views). Add normalizeTimestamp()
  helper for non-v3 paths that may store space-separated timestamps.

- #179: Strip internal fields (decoded_json, direction, payload_type,
  raw_hex, route_type, score, created_at) from ObservationResp. Only
  expose id, transmission_id, observer_id, observer_name, snr, rssi,
  path_json, timestamp — matching Node.js parity.

- #180: Remove _parsedDecoded and _parsedPath from node detail
  recentAdverts response. These internal/computed fields were leaking
  to the API. Updated golden shapes.json accordingly.

- #181: Use mux route template (GetPathTemplate) for perf stats path
  normalization, converting {param} to :param for Node.js parity.
  Fallback to hex regex for unmatched routes. Compile regexes once at
  package level instead of per-request.

fixes #178, fixes #179, fixes #180, fixes #181

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-27 18:09:36 -07:00
Kpa-clawbot
df63efa78d fix: poll new observations for existing transmissions (fixes #174)
The poller only queried WHERE t.id > sinceID, which missed new
observations added to transmissions already in the store. The trace
page was correct because it always queries the DB directly.

Add IngestNewObservations() that polls observations by o.id watermark,
adds them to existing StoreTx entries, re-picks best observation, and
invalidates analytics caches. The Poller now tracks both lastTxID and
lastObsID watermarks.

Includes tests for v3, v2, dedup, best-path re-pick, and
GetMaxObservationID.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-27 17:26:26 -07:00
Kpa-clawbot
95afaf2f0d fix(go): add nested packet field to WS broadcast, fixes #162
The frontend packets.js filters WS messages with m.data?.packet and
extracts m.data.packet for live rendering. Node's server.js includes
a packet sub-object (packet: fullPacket) in the broadcast data, but
Go's IngestNewFromDB built the data flat without a nested packet field.

This caused the Go staging packets page to never live-update via WS
even though messages were being sent — they were silently filtered out
by packets.js.

Fix: build the packet fields map separately, then create the broadcast
map with both top-level fields (for live.js) and nested packet (for
packets.js). Also fixes the fallback DB-direct poller path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-27 13:31:37 -07:00
Kpa-clawbot
6ec00a5aab test(go): fix failing test + add 18 tests, coverage 91.5% → 92.3%
Fix TestStoreGetAnalyticsChannelsNumericHash: corrected observation
transmission_id references (3,4,5 → 4,5,6) and changed assertion to
only check numeric-hash channels (seed data CHAN lacks channelHash).

New tests covering gaps:
- resolvePayloadTypeName unknown type fallback
- Cache hit paths for Topology, HashSizes, Channels
- GetChannelMessages edge cases (empty, offset, default limit)
- filterPackets: empty region, since/until, hash-only fast path,
  observer+type combo, node filter
- GetNodeHashSizeInfo: short hex, bad hex, bad JSON, missing pubKey,
  public_key field, flip-flop inconsistency detection
- handleResolveHops: empty param, empty hop skip, nonexistent prefix
- handleObservers error path (closed DB)
- handleAnalyticsChannels DB fallback (no store)
- GetChannelMessages dedup/repeats
- transmissionsForObserver from-slice filter path
- GetPerfStoreStats advertByObserver count
- handleAudioLabBuckets query error path

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-27 13:13:31 -07:00
Kpa-clawbot
1457795e3e fix: analytics channels + uniqueNodes mismatch
fixes #154: Go analytics channels showed single 'ch?' because
channelHash is a JSON number (from decoder.js) but the Go struct
declared it as string. json.Unmarshal failed on every packet.
Changed to interface{} with proper type conversion. Also fixed
chKey to use hash (not name) for grouping, matching Node.js.

fixes #155: uniqueNodes in topology analytics used hop resolution
count (phantom hops inflated it). Both Node.js and Go now use
db.getStats().totalNodes (7-day active window), matching /api/stats.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-27 12:07:50 -07:00
Kpa-clawbot
4101dc1715 test(go): push Go server test coverage from 77.9% to 91.4% (#145)
Add comprehensive coverage_test.go targeting all major coverage gaps:
- buildPacketWhere: all 8 filter types (0% -> covered)
- QueryMultiNodePackets: DB + store paths (0% -> covered)
- IngestNewFromDB: v3/v2 schema, dedup, defaults (0% -> covered)
- MaxTransmissionID: loaded + empty store (0% -> covered)
- handleBulkHealth DB fallback (24.4% -> covered)
- handleAnalyticsRF DB fallback (11.8% -> covered)
- handlePackets multi-node path (63.5% -> covered)
- handlePacketDetail no-store fallback (71.1% -> covered)
- handleAnalyticsChannels DB fallback (57.1% -> covered)
- detectSchema v2 path (30.8% -> covered)
- Store channel queries, analytics, helpers
- Prefix map resolve with GPS preference
- wsOrStatic, Poller, perfMiddleware slow queries
- Helper functions: pathLen, floatPtrOrNil, nilIfEmpty, etc.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-27 11:23:27 -07:00