This commit is contained in:
2026-04-08 16:09:26 +04:00
parent 33896daf77
commit 60037edf21
2 changed files with 37 additions and 13 deletions
+4 -2
View File
@@ -131,6 +131,8 @@ export async function loadMonitors(pageId: string, window: Window): Promise<Moni
// silently broken), aggregate directly from pings. Bounded by the window so
// it stays cheap. Once the rollup catches up this branch never fires.
if (rollupRows.length === 0) {
// Group/order by ordinals — Postgres won't dedupe a $-parameterised
// date_trunc() between SELECT and GROUP BY otherwise.
rollupRows = await sql<any[]>`
SELECT
monitor_id,
@@ -141,8 +143,8 @@ export async function loadMonitors(pageId: string, window: Window): Promise<Moni
FROM pings
WHERE monitor_id = ANY(${sql.array(ids)}::text[])
AND checked_at > date_trunc(${truncUnit}, now()) - ${intervalLiteral}::interval
GROUP BY monitor_id, date_trunc(${truncUnit}, checked_at)
ORDER BY monitor_id, bucket_start ASC
GROUP BY 1, 2
ORDER BY 1, 2 ASC
`;
}
// Index actual rollup data by (monitor_id, isoBucketStart) so we can fill in