Possible N+1 query in a loop
Part of Code Quality & Syntax, which counts for 20% of the overall score. When this check fires it deducts 8 points from that category, once per scan, no matter how many places it turns up.
What it detects
A .each loop calls a chained method on its block variable that looks like an association traversal, and the file has no .includes/.eager_load/.preload anywhere: the classic N+1 query shape. This is a heuristic, it cannot see the schema, so it can also flag a loop over plain in-memory data.
Why it matters
A loop that calls an association method on every element issues one extra database query per iteration instead of one query for the whole batch, so a page that lists 100 records can run 101 queries. This is one of the most common causes of slow, database-bound Rails requests, and it gets worse in direct proportion to how much data grows, often unnoticed until production traffic is much higher than in development or test.
How to fix it
Add .includes(:association_name) (or .eager_load / .preload for cases that need a specific join strategy) to the query that produces the collection being iterated, so the association is loaded in one extra query instead of one per row. Run the Bullet gem or check the SQL log in development to confirm the query count actually stops scaling with the row count afterward.
The paid report includes a ready-to-paste prompt for your AI coding agent for every check it finds, pointed at the exact findings from your scan. See pricing
Does your repo trip this check?
Paste a GitHub URL or drop a project folder. Scans run in your browser and take seconds.
Scan your repo