Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to automatically identify n+1 queries in a django app?

Is there any tool, plugin or technique that I can use to help identify n+1 queries on a Django application? There is a gem called bullet for Rails that identifies n+1 queries and logs or pops up warnings in a number of ways but I haven't been able to find anything similar for Django. I'd be open to guidance on how to write my own plugin if no one knows of an existing solution.

like image 632
ashanbrown Avatar asked Oct 30 '25 11:10

ashanbrown


2 Answers

nplusone does this

Auto-detecting the n+1 queries problem in Python

https://github.com/jmcarp/nplusone

comes with proper django support! also integrates with flask, vanilla wsgi, ...

like image 125
Carsten Avatar answered Nov 01 '25 01:11

Carsten


I don't know any plugin that would find them automatically and warn you.

I personally use the Django Debug Toolbar: https://github.com/django-debug-toolbar/django-debug-toolbar

It shows the number of queries ran on a page and you can view them.

like image 36
François Constant Avatar answered Nov 01 '25 03:11

François Constant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!