FORGE-85: latestPerGroup() replaces DISTINCT ON at 11 sites #701
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
gmackie/ForgeGraph!701
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "FORGE-85-latest-per-group"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part 2 of FORGE-85 (D1 Phase 2, parent FORGE-69). Stacked on #696. No behaviour change.
latestPerGroup()in@forgegraph/db(packages/db/src/latest-per-group.ts): the caller's select carries arow_number() over (partition by … order by …)column; the helper wraps it as a subquery, keeps rank 1, orders by the partition keys (as DISTINCT ON did) and strips the rank. Portable to SQLite/D1.latestHeadBuilds/TestRuns/Reviews), attestation-engine.ts + routers/review.ts (sharedlatestVerdictsByAuthor), fleet.ts deployments (latestDeploymentPerApp), load-workspace-public-feed.ts deployments, delivery-alert-sweep.ts (3), monitoring/evaluate straggler builds (moved tolib/latest-changeset-builds.ts, since route modules can't export helpers).apps.id/changesets.id,builds.status/changesets.status). The approved-changeset ordering keeps PG'sasc nulls lastexplicitly (SQLite sorts NULLs first by default).Verification
packages/api/src/__tests__/latest-per-group.database.test.ts(7) andapps/web/src/lib/__tests__/latest-per-group.database.test.ts(5) assert each new query equals the verbatim old DISTINCT ON query on fixtures with multiple rows per group, filtered rows, id tiebreakers and a NULL left join. Green on PGlite and on Postgres 16.🤖 Generated with Claude Code
c9b90ecca4a7c14b7c82