Last active
March 22, 2020 02:02
-
-
Save RodrigoCMoraes/a51df8ba26ac44d4fa76ca4619ecd882 to your computer and use it in GitHub Desktop.
Function to get the amount of queries of django query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def amount_queries(): | |
"""Usage: | |
start_num_queries = amount_queries() | |
... plent of code with django orm queries | |
end_num_queries = amount_queries() | |
num_queries = end_num_queries - start_num_queries | |
""" | |
from django.db import connection | |
from django.conf import settings | |
settings.DEBUG = True # side effect | |
num_queries = len(connection.queries) | |
return num_queries |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment