Files
loki/scripts
CatoandClaude Opus 5.5 bec2a9d67c perf(runs): fetch the latest run per path, not every run ever made (#873)
getLatestRunsByProjectPaths selected every run for every path and kept
the first per path in JS. Measured on production today for the busiest
user: 699 rows at ~1.26 KB each (~880 KB, mostly `summary` JSON) fetched
and parsed to keep 32. Control paid that on every poll; since #863 the
/today front door pays it on every load, and it grows with every run.

Postgres time was ~2 ms either way, so the cost was transfer and parsing.
DISTINCT ON (project_path) returns only the 32 rows the caller keeps.
The repo already uses selectDistinctOn on this table (register/load-map).

Equivalence checked against production data before changing it: the old
and new selection pick the same run for all 36 (user, path) pairs, with
0 mismatches; there are 0 ties on the latest started_at and 0 NULL
started_at values, so neither tie-breaking nor NULL ordering can differ.
The drizzle-generated SQL (via .toSQL()) was run read-only on prod and
returned 32 rows.

Gate: latest-run-is-one-row-per-path.ts pins both halves. The ORDER BY
must lead with the DISTINCT ON column or Postgres rejects the query at
runtime, which tsc cannot see and both callers would swallow into an
empty map, so run health would silently stop reporting. Proven by
mutation both ways.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 02:34:52 -07:00
..
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00
2026-08-31 09:23:30 +00:00