Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'dev' of github.com:pculture/unisubs into dev

  • Loading branch information...
commit 2770774b1a9a83508749df47def6634bf41da433 2 parents a3b1ad3 + 20a6d61
@fernandotakai fernandotakai authored
Showing with 23 additions and 1 deletion.
  1. +23 −1 middleware.py
View
24 middleware.py
@@ -201,16 +201,37 @@ def _show_toolbar(self, request):
return False
return True
+
# I'm so sorry about this.
import django.db.backends.mysql.base
from django.db.backends.mysql.base import CursorWrapper as _CursorWrapper
class MetricsCursorWrapper(_CursorWrapper):
+ def _query_type(self, query):
+ if not query:
+ return 'UNKNOWN'
+ elif query.startswith('SELECT COUNT(*) '):
+ return 'COUNT'
+ elif query.startswith('SELECT '):
+ return 'SELECT'
+ elif query.startswith('DELETE '):
+ return 'DELETE'
+ elif query.startswith('INSERT '):
+ return 'INSERT'
+ elif query.startswith('UPDATE '):
+ return 'UPDATE'
+ else:
+ return 'OTHER'
+
def execute(self, query, params=None):
+ op = self._query_type(query)
+
with Timer('db-query-time'):
- return super(MetricsCursorWrapper, self).execute(query, params)
+ with Timer('db-query-time.%s' % op):
+ return super(MetricsCursorWrapper, self).execute(query, params)
def executemany(self, query, params_list):
+ op = self._query_type(query)
start = time.time()
try:
@@ -226,6 +247,7 @@ def executemany(self, query, params_list):
for _ in xrange(len(params_list)):
ManualTimer('db-query-time').record(ms_per_query)
+ ManualTimer('db-query-time.%s' % op).record(ms_per_query)
django.db.backends.mysql.base.CursorWrapper = MetricsCursorWrapper
Please sign in to comment.
Something went wrong with that request. Please try again.