☆ 12 r/databases ·by Mike ·2026-10-31 How do you spot N+1 queries before production? 772 views Our ORM makes 300 queries on a page with a list of orders. Tests pass because they use a tiny dataset. What tooling do you use to catch this? ⧉ Copy link⚑ Report
☆ 0 S Sofia ·2026-10-31#1 Log every SQL statement in test with a query counter and assert an upper bound per request. It is crude and very effective. ⧉ Copy link⚑ Report
☆ 0 M Mike ·2026-10-31#2 We use Django Debug Toolbar locally but it is not in CI. ⧉ Copy link⚑ Report
☆ 0 L Laura ·2026-11-01#3 Add a middleware that counts queries and fails the test if the count exceeds a threshold. Django has assertNumQueries, but a global ceiling catches more. ⧉ Copy link⚑ Report
3 replies