mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-10-17 00:39:51 +00:00
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.
20 lines
980 B
SQL
20 lines
980 B
SQL
-- name: GetPathStats :many
|
|
-- All HTTP aggregates read the hourly rollup, never observations.
|
|
WITH readings AS (
|
|
SELECT iata, hour, category, hash_bytes, entries, receptions FROM analytics_hourly_paths
|
|
WHERE hour >= @since::timestamptz AND hour < @until::timestamptz
|
|
AND COALESCE(cardinality(@iatas::bpchar[]), 0) = 0
|
|
UNION ALL
|
|
SELECT iata, hour, category, hash_bytes, entries, receptions FROM analytics_hourly_paths
|
|
WHERE hour >= @since::timestamptz AND hour < @until::timestamptz
|
|
AND cardinality(@iatas::bpchar[]) > 0 AND iata = ANY(@iatas::bpchar[])
|
|
)
|
|
SELECT (grouping(hour) = 0)::boolean AS is_hourly,
|
|
COALESCE(hour, 'epoch'::timestamptz)::timestamptz AS hour,
|
|
category, hash_bytes, COALESCE(entries, 0)::integer AS entries,
|
|
sum(receptions)::bigint AS receptions
|
|
FROM readings
|
|
GROUP BY GROUPING SETS ((category, hash_bytes, entries), (hour, category, hash_bytes))
|
|
ORDER BY is_hourly, hour, category, hash_bytes, entries;
|
|
|