DEV Community

Bedirhan Elibol
Bedirhan Elibol

Posted on

How do you catch N+1 queries before production?

Our test database has ten rows, so every page feels instant. An N+1 only shows up once a table has real data, and by then the page is timing out.

Two things have worked for me: query logging in development, where the same query repeating with only the id changing gives it away, and a test that seeds 50 rows and asserts the query count matches the count with 5.

What do you use? Bullet, a DataLoader, APM traces, code review? I'm curious which of them catches the case where the loop is in a component and the query is hidden in a helper.

Top comments (0)