Repository navigation
Description
What happens
GET /api/v1/.../work-items/?expand=assignees looks each distinct assignee up one at a time:
// crates/thrust-api-v1/src/work_items.rs:206-213 (as of 1991731)
if wanted.contains("assignees") {
let people: BTreeSet<UserId> = rows.iter().flat_map(|r| r.attrs.assignee_ids.iter().copied()).collect();
let mut briefs = HashMap::new();
for user in people {
briefs.insert(user, user_brief(ctx, user).await?);
}
x.assignees = Some(briefs);
}user_brief (:165) awaits user_by_id and then profile, so each assignee costs two statements, one after the other.
A list costs its own statements plus 2 x (distinct assignees on the page).
The cost is bounded only by the page and the project: a page holds up to 1000 items (MAX_PER_PAGE, also the default), and the
distinct assignees on it are at most the project's members. A page spread over 10 people sends the list's 4 statements plus 20.
Each statement is one round trip from the Worker to the database, which FR-08 item 2 budgets at 5 for a list.
The single-item reads (shown, :218) pay the same for that one item's assignees.
Why it is open
The budget test from #108 holds the default shape of each list and leaves expand out (the test's header and G-24 in
docs/src/testing/status.md record it as a known gap). It has not been measured with assignees; the figure above is from reading the code.
Probably also over budget (not measured: read from the code)
?expand=state and ?expand=labels each add one statement (project_states, project_labels). /api/v1 work items are at 4
by default, so ?expand=state,labels should be 6, one over the budget, with no assignees at all. Measure before fixing.
Proposal
- Measure first. Extend
crates/thrust-contract-tests/tests/budget/mod.rsover every subset ofexpand
(state,labels,assignees: eight cases) and over 0, 1 and 5 distinct assignees, on a list seeded with six or more items.
The property that fails today: the count does not depend on how many assignees there are. Run it onmainfirst and record
the red result (expected: assignees 1 vs 5 differ by 8). - Batch the lookup. A port method that reads the users and profiles of a set of ids in one statement
(WHERE id = ANY($1), profiles joined), in both adapters;expansioncalls it once. An empty set sends nothing. - Decide what the budget means for expanded lists. Even batched,
state,labels,assigneesis 4 + 3 = 7. Either the three
expansions fold into fewer statements (one query for all of them), or the budget for an expanded list is stated as its own
number. That is the owner's call under FR-08; the issue should not pick it silently. pg_adapter's counting tests get one for the new method: exactly 1 statement for any set size.- When it holds: drop the gap from G-24, the header of the budget test,
docs/src/flows/app.mdand
docs/src/testing/techniques/contract-suite.md.
Acceptance
- The budget test covers the eight
expandsubsets on/api/v1work items, with several distinct assignees, onnative-pgandworker-cf. - It failed on
mainbefore the change (the red run is in the PR description) and passes after it. - The count of a list does not grow with the number of distinct assignees.
- The budget for an expanded list is written down (in
status.mdG-24) with the owner's decision.
Refs: #39
Activity