n-plus-one-hunterlisted
Install: claude install-skill windchillscalanthes-ship-it/n-plus-one-hunter
# N+1 Query Hunter
Catch the loop that silently fires one database query per row — and turn it into
a constant number of queries before it reaches production.
A single innocent-looking line inside a loop (`post.author.name`,
`order.items.count`, `user.profile.avatar`) issues a fresh query on every
iteration. Render 50 posts and you've run 51 queries where 2 would do. It passes
review, passes tests (which seed 3 rows), and then the endpoint that lists 500
rows takes four seconds and melts the database under load. This skill reviews the
code, explains exactly *what* loops and *how many* queries it costs as a function
of N, and produces the eager-loaded rewrite.
## When to use this
- You are **writing** code that loads a collection and reads an association.
- You are **reviewing** a controller, serializer, resolver, view, or job in a diff.
- An endpoint or page got **slow**, or a background job is hammering the database.
- Someone asks "why is this making so many queries?", "is this an N+1?", or
"how do I eager-load this?".
If the collection is small and bounded (a handful of config rows, a fixed-size
lookup), an N+1 may be harmless — say so and don't over-engineer. The metric is
whether the query count **grows with the data**.
## Workflow
1. **Establish context.** Identify the **ORM** and **framework** (and version if
you can — eager-load APIs and defaults differ), and the **entry point**: a
controller action, serializer, GraphQL resolver, view template, or job.