Spent an afternoon this week chasing down why a client's order dashboard took around 2.5s to load.
Turned out the page was firing 300+ database queries. Classic N+1 problem. Every order in the loop was making its own separate trip to the DB just to grab the customer and product.
One line fixed it. select_related() tells Django to pull the related rows in a single JOIN instead of querying them one at a time.
312 queries down to 3. Page load went from 2.4s to 0.08s.
The annoying part is this never shows up on small datasets in dev. It only bites you in production once the table grows. So now I always check the query count in Django Debug Toolbar before shipping any list view.
What's the worst N+1 you've run into?
Like this project
Posted Jul 4, 2026
Spent an afternoon this week chasing down why a client's order dashboard took around 2.5s to load.
Turned out the page was firing 300+ database queries. Clas...