-
Notifications
You must be signed in to change notification settings - Fork 0
/
mixins.py
29 lines (22 loc) · 836 Bytes
/
mixins.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class ProfilingMixin(object):
def dispatch(self, request, *args, **kwargs):
from time import time
from django.db import connection
from django.conf import settings
response = super(ProfilingMixin, self).dispatch(request, *args, **kwargs)
if not settings.DEBUG:
return response
render_start = time()
response.render()
rendering_time = time() - render_start
response.data["__meta__"] = {
"database": {
"queries_count": len(connection.queries),
"execution_time": sum([float(query["time"]) for query in connection.queries])
},
"templating": {
"rendering_time": rendering_time
}
}
response._is_rendered = False
return response