perf(httpapi): GET /instances forks one git rev-list per active row for commits_behind #152
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Cloonar/coding-lab#152
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Raised while landing PR #150 (issue #149). Not a bug today — filing for a maintainer call on whether the cost is acceptable as the fleet grows.
What
The
commits_behindbadge is computed per row on the instances dashboard:and
Server.commitsBehind(internal/httpapi/runs.go:112-121) shells out togitx.CommitsBehind→git rev-list --count. SoGET /api/v1/instancesforks onegitsubprocess per active instance row, every time it is called.The accompanying comment says:
That is true of the SQL — and the comment is a fair description of what it set out to fix — but it reads as though the endpoint is O(1) overall, which it is not: the git subprocesses are genuinely per-row. Whatever is decided here, that comment should be corrected, because it currently vouches for a property the endpoint does not have.
Why it might matter
/instancesis a hot endpoint: the SPA refetches it on everyrun.changed(which #149 itself newly publishes from crmerge on every CR merge) and on debouncedrun.messages.changed. So the fork count isactive_instances × refetch_rate, and #149 added a new event source driving that rate.Today active instances are few and
rev-list --counton a bare repo is milliseconds, so this is comfortably fine. It gets less comfortable with a larger fleet or a chattier event stream.Options (for triage)
commandsCacheTTL) — the count only changes when a fetch advances a base ref, so it is very cacheable.commitsBehindalready documents, and takes git out of the request path entirely.No action needed if the answer is "fine at this scale" — but the comment fix should happen either way.