Files
beacon-server/db/presence.go
T
MrAlders0n 98006a9364 feat(stats): serve historical stats from hourly rollups
Stats endpoints read hourly rollup tables filled once per closed hour by one
advisory-locked task, instead of materialized views that re-scanned every
observation on each refresh. IATA-set tables give exact distinct counts for any
IATA set or region. Cleanup holds raw rows for unrolled hours (up to 24h).

Adds /stats/series; ingest keeps packet observation counts, observer last IATA,
channel message counts and trace tag summaries. 001_baseline.sql is rewritten,
so pre-release 2.0 databases must be recreated. See docs/historical-stats.md.
2026-10-02 07:43:56 -04:00

56 lines
1.5 KiB
Go

// Copyright 2026 Beacon Contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
package db
import (
"context"
"time"
sqlc "github.com/MeshCore-Beacon/beacon-server/db/sqlc"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
)
func (s *Store) TouchObservers(ctx context.Context, ids []uuid.UUID, seen []time.Time, counts []int32, iatas []string, iataAts []time.Time) error {
return s.q.TouchObservers(ctx, sqlc.TouchObserversParams{
Column1: ids,
Column2: toTimestamptzs(seen),
Column3: counts,
Column4: iatas,
Column5: nullableTimes(iataAts),
})
}
func (s *Store) TouchObserverBrokers(ctx context.Context, ids []uuid.UUID, brokers []string, seen, packets []time.Time) error {
return s.q.TouchObserverBrokers(ctx, sqlc.TouchObserverBrokersParams{
Column1: ids,
Column2: brokers,
Column3: toTimestamptzs(seen),
Column4: nullableTimes(packets),
})
}
func (s *Store) TouchPackets(ctx context.Context, hashes [][]byte, heard []time.Time) error {
return s.q.TouchPackets(ctx, sqlc.TouchPacketsParams{
Column1: hashes,
Column2: toTimestamptzs(heard),
})
}
func toTimestamptzs(ts []time.Time) []pgtype.Timestamptz {
out := make([]pgtype.Timestamptz, len(ts))
for i, t := range ts {
out[i] = pgtype.Timestamptz{Time: t, Valid: true}
}
return out
}
func nullableTimes(ts []time.Time) []pgtype.Timestamptz {
out := make([]pgtype.Timestamptz, len(ts))
for i, t := range ts {
out[i] = pgtype.Timestamptz{Time: t, Valid: !t.IsZero()}
}
return out
}