Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(coderd): add queue-position-free provisioner job query - #28367

Merged
spikecurtis merged 1 commit into
mainfrom
spikecurtis/job-without-queue-position
Aug 24, 2026
Merged

feat(coderd): add queue-position-free provisioner job query#28367
spikecurtis merged 1 commit into
mainfrom
spikecurtis/job-without-queue-position

Conversation

@spikecurtis

Copy link
Copy Markdown
Contributor

Follow-up to #28302 (GRU-82, RFC). That PR added related-data selection but noted that selecting latest_build.job still ran the expensive GetProvisionerJobsByIDsWithQueuePosition query, which computes queue position and size with window functions over pending jobs and provisioner daemons and is consistently the top resource consumer in scale tests.

This PR adds a cheaper GetProvisionerJobsByIDs query that fetches jobs by ID without the queue-position computation, and selects between the two based on whether latest_build.job.queue_position is requested. When the queue position is not selected, QueuePosition and QueueSize are left zero and the rest of the response is unchanged.

Both paths go through a single provisionerJobsByIDs API method that takes the jobRelated selection, switches on it, and reshapes the cheaper query's rows into GetProvisionerJobsByIDsWithQueuePositionRow so downstream conversion is uniform.

The new query has the same dbauthz properties as the queue-position variant (system-level pass-through pending the proper provisioner-job RBAC check tracked in #16160), with a matching authorization test.

No behavior change for existing callers: they select queue_position (via allLatestBuildRelated), so they continue to use the queue-position query.


Generated by Coder Agents on behalf of @spikecurtis.

@spikecurtis
spikecurtis requested a review from cstyan August 20, 2026 09:38
@spikecurtis
spikecurtis marked this pull request as ready for review August 20, 2026 09:39
Comment on lines +756 to +759
// Fetches provisioner jobs by their IDs without computing queue position or
// queue size. Callers that do not need the queue position should prefer this
// over GetProvisionerJobsByIDsWithQueuePosition, whose window functions over
// pending jobs and provisioner daemons are comparatively expensive.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I don't think having a comment here (at least not one this long) is really necessary

Comment thread coderd/workspacebuilds.go
Comment on lines +1132 to +1139
jobs := make([]database.GetProvisionerJobsByIDsWithQueuePositionRow, 0, len(provisionerJobs))
for _, job := range provisionerJobs {
jobs = append(jobs, database.GetProvisionerJobsByIDsWithQueuePositionRow{
ID: job.ID,
CreatedAt: job.CreatedAt,
ProvisionerJob: job,
})
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I imagine there's not a nice way to do it, and we'll probably clean things up at their call sites in a follow up PR anyways, but it would be nice if we had a way to have Database.GetProvisionerJobsByIDs to return database.GetProvisionerJobsByIDsWithQueuePositionRow directly so we didn't have to do additional allocations inline here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the methods and their return types are autogenerated by sqlc, so I think it would be hard.

Fortunately these are not pointer types, so we get one allocation for the slice and we're good to go.

@spikecurtis
spikecurtis merged commit 6a58d50 into main Aug 24, 2026
55 of 56 checks passed
@spikecurtis
spikecurtis deleted the spikecurtis/job-without-queue-position branch August 24, 2026 14:17
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants