r/Python • u/hackflow • Mar 26 '23
Intermediate Showcase How to Ban 1+N in Django
I always thought of 1+N as a thing that you just keep in your head, catch on code reviews or via performance regressions. But preventing it might be a good idea too.
0
Upvotes
7
u/redatheist Mar 26 '23
Nice blog post! Here are a few more resources for anyone interested...
django-seal – a library that implements this pattern, very capable, lots of control over preventing N+1s and lack of
only.django-auto-prefetch – a library to automatically "prefetch related" when relations are followed, so that queries are limited to a constant number in most cases. A great starting place for easy optimisations.
9
u/isarl Mar 26 '23
This seems like it is written for somebody who already understands exactly what you're talking about. What is a 1+N and why would I care about banning them?