Store a new row's earliest timestamp as first_seen (closes #112)
check / check (push) Canceled after 0s

Each handler took the latest time per key in a batch and inserted it as
a new row's first_seen, so a key updated twice in one batch, seconds
apart, was stored first seen at the later time, and the IP lookup could
answer with a prefix first_seen after the route's last_seen.

The prefix handler now keeps the earliest time of all of the batch's
updates for each prefix. The AS, peer and peering handlers keep the
earliest and the latest time per key in database.SeenTimes, and
GetOrCreateASNBatch, UpdatePeerBatch and RecordPeering store a new row
first seen at the earliest and last seen at the latest. A stored row
still has only its last_seen set, to the latest.

Model: opus-5-5
This commit was merged in pull request #137.
This commit is contained in:
2026-10-20 02:59:17 +02:00
parent c4dadd1477
commit 444457bcf8
15 changed files with 384 additions and 103 deletions
+9 -7
View File
@@ -229,19 +229,21 @@ func (h *ASHandler) flushBatch() {
return
}
// Process ASNs first (deduped)
asnMap := make(map[int]time.Time)
// The earliest and the latest time the batch saw each AS. The batch holds
// several updates for an AS, from many peers, so a new AS is stored first
// seen at the earliest of them and last seen at the latest.
asns := make(map[int]database.SeenTimes)
for _, op := range batch {
if existing, ok := asnMap[op.number]; !ok || op.timestamp.After(existing) {
asnMap[op.number] = op.timestamp
}
seen := asns[op.number]
seen.Add(op.timestamp)
asns[op.number] = seen
}
// Process all ASNs in a single batch transaction
err := h.db.GetOrCreateASNBatch(asnMap)
err := h.db.GetOrCreateASNBatch(asns)
if err != nil {
h.logger.Error("Failed to process ASN batch",
"error", err, "count", len(asnMap))
"error", err, "count", len(asns))
}
h.mu.Lock()