Skip to content

test: assert exact query counts in upcoming_events_for_user specs - #3095

Merged
mroderick merged 1 commit into
masterfrom
3094-tighten-upcoming-events-query-counts
Nov 11, 2026
Merged

mroderick merged 1 commit into
masterfrom
3094-tighten-upcoming-events-query-counts

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Closes #3094.

Both query-count regression specs for upcoming_events_for_user now assert exact equality, instead of allowing two extra queries at four workshops than at one. Measured on both paths: 6 queries at one workshop, 6 at four. The slack would hide a constant added query, which is the shape a preload falling back to a non-batched load takes.

The chapter-workshops spec had a second hole: it read host after the counted block closed, so deleting preload(workshop_host: :sponsor) from chapter_workshops_for left both counts equal and the example green. It now counts the host reads, which is what the invitations spec already does.

Review notes

  • Look first at the restructured chapter-workshops example. The warmup call is gone, and load_user_events_and_count_host_queries now covers the load, the host reads, and the host assertion inside the measured window. The count is 6 either way.
  • Removing either preload now fails its example.
  • Deliberately not done: absolute query-count caps and SQL-shape assertions. Both came up in review and stayed out; they pin numbers or SQL text that this guard does not need, and the sibling .upcoming_events spec uses the same relative shape.
Measured counts and review findings

Measured on this branch, both paths, before and after the change:

Path 1 workshop 4 workshops
chapter workshops 6 6
accepted invitations 6 6

Guard check, by deleting one preload at a time and running the spec file:

  • Drop preload(workshop_host: :sponsor) from chapter_workshops_for: the chapter example now fails (it passed before this change).
  • Drop preload(workshop: { workshop_host: :sponsor }) from accepted_workshops_for: the invitations example fails, as it did before.

A four-persona review pass (correctness, standards, testing, adversarial) plus an independent validator produced one blocker, fixed here: the chapter example's host reads sat outside the counted window. Two P3 notes were left open deliberately: count_queries reports totals only, so a failure does not name the new SQL; and no absolute cap exists, so a uniformly added query passes both sides equally. The validator agreed with those dispositions.

Both regression specs allowed up to two extra queries at four workshops
than at one. That slack leaves room for a constant added query, the shape
a preload falling back to a non-batched load takes. Measured on both
paths: 6 queries at one workshop, 6 at four, so exact equality holds.

The chapter-workshops spec also read host outside the counted block, so
removing that preload kept both counts equal and left the guard green.
It now counts the host reads too, which is how the invitations spec
already behaves.
@mroderick
mroderick marked this pull request as ready for review November 11, 2026 11:57
@mroderick
mroderick merged commit 08cf4e7 into master Nov 11, 2026
12 checks passed
@mroderick
mroderick deleted the 3094-tighten-upcoming-events-query-counts branch November 11, 2026 11:58
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.

Tighten query-count assertions in the upcoming_events_for_user specs

1 participant