Search docs
Docs searchValidation rule
Back to Rule CatalogAP-DQR-005Data / Query RiskN+1 query evidence in collection loop
Flags collection workflows that appear to query inside a loop.
warningviolationNo auto-fix
How to fix
- Batch-load related records.
- Use include/select or joins where appropriate.
- Add tests or traces for collection-size behavior.
What it means
A request path likely performs one query for each item in a collection.
Why it matters
N+1 queries become slow and expensive as collection size grows.
Common causes
- Related data is fetched per row.
- A loop calls a repository method repeatedly.
- Batch loading was not added for a new relationship.
Example bad pattern
for each repository, query latest snapshot separately.Example good pattern
Fetch latest snapshots for all repository ids in one bounded query.Related files/config
apps/api/srcpackages/db/prisma/schema.prisma
Related CLI commands
archpilot validatearchpilot validate --ci