3 ms·
I agree that this stuff can definitely be handled better. https://github.com/django-query-profiler/django-query-profiler https://github.com/django-query-profil
by simonw 5y ago
I agree that this stuff can definitely be handled better.
https://github.com/django-query-profiler/django-query-profiler https://github.com/django-query-profiler/django-query-profil... has a neat option for detecting likely N+1 queries. I usually use the Django Debug Toolbar for this.
Django's ".only()" method lets you specify just the columns you want to retrieve - with the downside that any additional property access can trigger another SQL query. I thought I'd seen code somewhere that can turn those into errors but I'm failing to dig it up again now.
I've used the assertNumQueries() assertion in tests to guard against future changes that accidentally increase the number of queries being made without me intending that.
The points you raise are valid, but there are various levels of mitigations for them. Always room for improvement though!
- benhoyt 5y agoThanks for the thoughtful responses and the link -- Django Query Profiler looks nice!