mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-09-01 16:48:19 +00:00
fix(traces): review fixes for trace_iatas
Refresh last_heard on duplicate observations too, capped at hourly, so steady traffic can't age a trace out of the filter (dedup key has no heard_at). Drop the unused last_heard index column so upserts stay HOT, and share one retention cutoff across the cleanup deletes.
This commit is contained in:
@@ -236,6 +236,7 @@ type Querier interface {
|
||||
UpsertPacket(ctx context.Context, arg UpsertPacketParams) (UpsertPacketRow, error)
|
||||
UpsertRegion(ctx context.Context, arg UpsertRegionParams) (int32, error)
|
||||
UpsertRegionIATA(ctx context.Context, arg UpsertRegionIATAParams) error
|
||||
// Refreshes at most hourly so repeat hears don't churn the row.
|
||||
UpsertTraceIATA(ctx context.Context, arg UpsertTraceIATAParams) error
|
||||
// ============================================================
|
||||
// TRANSPORT CODES
|
||||
|
||||
@@ -4072,7 +4072,8 @@ const upsertTraceIATA = `-- name: UpsertTraceIATA :exec
|
||||
INSERT INTO trace_iatas (trace_tag, iata, last_heard)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (trace_tag, iata) DO UPDATE SET
|
||||
last_heard = GREATEST(trace_iatas.last_heard, EXCLUDED.last_heard)
|
||||
last_heard = EXCLUDED.last_heard
|
||||
WHERE EXCLUDED.last_heard > trace_iatas.last_heard + INTERVAL '1 hour'
|
||||
`
|
||||
|
||||
type UpsertTraceIATAParams struct {
|
||||
@@ -4081,6 +4082,7 @@ type UpsertTraceIATAParams struct {
|
||||
LastHeard pgtype.Timestamptz `json:"last_heard"`
|
||||
}
|
||||
|
||||
// Refreshes at most hourly so repeat hears don't churn the row.
|
||||
func (q *Queries) UpsertTraceIATA(ctx context.Context, arg UpsertTraceIATAParams) error {
|
||||
_, err := q.db.Exec(ctx, upsertTraceIATA, arg.TraceTag, arg.Iata, arg.LastHeard)
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user