Skip to content

/costs reads the records of the visits it selects, and no others - #59

Closed
gedaiu wants to merge 1 commit into
mainfrom
fix/costs-read-only-scoped-records
Closed

gedaiu wants to merge 1 commit into
mainfrom
fix/costs-read-only-scoped-records

Conversation

@gedaiu

@gedaiu gedaiu commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Closes #52.

A cost summary built its record sums, its unpriced models and its billing mode over every station run's records, and only then joined them to the visits the filter had picked. So a summary for one run took as long as one for the whole database, and GET /assembly-runs/{id}, which asks for the cost of its run, took seconds with it.

The visits are now picked first, and the records are read for those alone, by the records' primary key. The figures and the response are unchanged. /metrics still sums every record, as it should.

On a scratch database of 30,000 visits and 600,000 records, through the real store: one run went from 321 ms to 3 ms, and a 30-minute span from 589 ms to 16 ms. The old time grows with the table and the new one does not, so the production figures in the issue should fall by the same factor; worth repeating the three requests there after the deploy.

A new store test pins that a run's summary names only its own unpriced model. The existing cost tests pass untouched. The group lists in the API README and in the storage doc were stale (no run, no billing_mode) and are corrected.

🤖 Generated with Claude Code

The filters applied to the visits only; the record sums, the unpriced
models and the billing mode were each built over every station run's
records first. A summary for one run took seconds, and so did
GET /assembly-runs/{id}, which asks for it.

The visits are picked first, and the records are read for those alone,
by their primary key. On 30,000 visits and 600,000 records one run went
from 321 ms to 3 ms.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@lore-agent

lore-agent Bot commented Oct 27, 2026

Copy link
Copy Markdown

Lore is reviewing this PR — 7351e5b1-9ed2-4c9f-9220-8945c7c0f1dc.

Submit a review that requests changes to have Lore push a fix for it. Comment @lore review to re-run the review.

@lore-agent lore-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lore review — Approved

Scopes CostsStore.summary record CTEs to the filtered station runs so per-run and filtered cost queries read only matching visits' records by primary key.

Must fix (0) · Consider (0) · Nits (0)

Reviewed by gemini-4-argon

Submit a review that requests changes to have Lore push a fix for it. Comment @lore review to re-run the review.

Posted by floor, visit 261c5e22-91a8-4615-9682-ad54310ccae1.

@gedaiu

gedaiu commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #79 (merged 2026-11-14, live since v0.5.2), which fixed the same query in packages/store/src/costs.ts and closed #52. Related: #79.

@gedaiu gedaiu closed this Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GET /assembly-runs/{id} takes 2 to 7 seconds per run while the list and the visits take milliseconds

1 participant