← ClaudeAtlas

n-plus-one-hunterlisted

Find and fix N+1 queries and related ORM query anti-patterns — the loop that quietly fires one database query per row. Reviews application code for N+1s, nested N+1s, count/exists-in-a-loop, cartesian eager-load blowups, over-fetching, and missing foreign-key indexes, then rewrites them with the correct eager-load strategy and shows the query-count before/after. Use whenever writing or reviewing code that loads a collection and touches an association, a serializer or API response, a GraphQL resolver, a view template, or a background job — in ActiveRecord/Rails, the Django ORM, Prisma, SQLAlchemy, Sequelize, TypeORM, Ecto, or raw query code — and especially before merging an endpoint that renders a list.
windchillscalanthes-ship-it/n-plus-one-hunter · ★ 0 · API & Backend · score 75
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.