Skip to content

Instantly share code, notes, and snippets.

@loic
Created February 3, 2014 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loic/8779822 to your computer and use it in GitHub Desktop.
Save loic/8779822 to your computer and use it in GitHub Desktop.
from django.db import connection
class QueryCountMiddleware(object):
def process_response(self, request, response):
duration = 0
for query in connection.queries:
duration += float(query['time'])
print ('%s\n' % query['sql'])
print('Total of %s queries in %s seconds.' % (len(connection.queries), duration))
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment