diff options
Diffstat (limited to 'debug_toolbar/panels/sql.py')
| -rw-r--r-- | debug_toolbar/panels/sql.py | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index 3903b54..0c9bc61 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -1,6 +1,6 @@ +from datetime import datetime import os import SocketServer -from datetime import datetime import traceback import django @@ -22,15 +22,45 @@ socketserver_path = os.path.realpath(os.path.dirname(SocketServer.__file__)) # get a copy of the toolbar object with access to its config dictionary SQL_WARNING_THRESHOLD = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}).get('SQL_WARNING_THRESHOLD', 500) +# Note: This isn't intended to catch ALL possible SQL keywords, just a good common set. +# Note: Subsets are listed last to avoid matching a subset of a keyword. This +# whole thing could be greatly improved but for now this works. SQL_KEYWORDS = ( - 'SELECT', + 'ALTER', + 'AND', + 'ASC', + 'AS', + 'AVG', + 'COUNT', + 'CREATE', + 'DESC', + 'DELETE', + 'DISTINCT', + 'DROP', 'FROM', - 'WHERE', + 'GROUP BY', + 'HAVING', 'INNER JOIN', + 'INSERT', + 'IN', 'LEFT OUTER JOIN', + 'LIKE', + 'LIMIT', + 'MAX', + 'MIN', + 'OFFSET', + 'ON', 'ORDER BY', - 'HAVING', - 'GROUP BY', + 'OR', + 'SELECT', + 'SET', + 'STDDEV_POP', + 'STDDEV_SAMP', + 'SUM', + 'UPDATE', + 'VAR_POP', + 'VAR_SAMP', + 'WHERE', ) def tidy_stacktrace(strace): @@ -43,7 +73,8 @@ def tidy_stacktrace(strace): trace = [] for s in strace[:-1]: s_path = os.path.realpath(s[0]) - if getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}).get('HIDE_DJANGO_SQL', True) and django_path in s_path and not 'django/contrib' in s_path: + if getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}).get('HIDE_DJANGO_SQL', True) \ + and django_path in s_path and not 'django/contrib' in s_path: continue if socketserver_path in s_path: continue @@ -78,7 +109,8 @@ class DatabaseStatTracker(util.CursorDebugWrapper): 'stacktrace': stacktrace, 'start_time': start, 'stop_time': stop, - 'is_slow': (duration > SQL_WARNING_THRESHOLD) + 'is_slow': (duration > SQL_WARNING_THRESHOLD), + 'is_select': sql.lower().strip().startswith('select'), }) util.CursorDebugWrapper = DatabaseStatTracker |
