Skip to content

Document N+1 query detection in integration tests - #568

Merged
imorland merged 3 commits into
mainfrom
im/document-n1-detection
Jul 31, 2026
Merged

Document N+1 query detection in integration tests#568
imorland merged 3 commits into
mainfrom
im/document-n1-detection

Conversation

@imorland

Copy link
Copy Markdown
Member

Documents the N+1 detection added in flarum/framework#4871: requests sent through the integration TestCase are checked for N+1 query patterns and the test fails when one is found.

Covers how to read a failure (including what the distinct-bindings count tells you — one query per record is an N+1, many repeats of one binding is a missed memoisation), and the escape hatches in preference order: allowedRepeatedQueries() for a single shape, detectsRepeatedQueries() for a test case, FLARUM_DETECT_REPEATED_QUERIES=0 for a whole run.

Should merge alongside or after flarum/framework#4871.

Companion to flarum/framework#4871, which fails integration tests whose
requests run N+1 queries. Explains how to read a failure, what the
binding count means, and how to exempt a legitimately repeated query
shape.
imorland added 2 commits July 31, 2026 21:02
Follows the two-tier behaviour in flarum/framework#4871: one query per
record fails the test, while a query repeated for the same few values
raises a warning instead.
Follows flarum/framework#4871: the example phpunit config now displays
warning details, and findings appear as pull request annotations and a run
summary in CI via FLARUM_REPEATED_QUERY_LOG.
@imorland
imorland merged commit a37c3e9 into main Jul 31, 2026
1 check passed
@imorland
imorland deleted the im/document-n1-detection branch July 31, 2026 21:01
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.

1 participant