Commit db98ef8f by Colin Howe

Add the ability to hide (costly) stacktraces

parent 0e05413c
...@@ -25,5 +25,10 @@ An extra panel titled "MongoDB" should appear in your debug toolbar. ...@@ -25,5 +25,10 @@ An extra panel titled "MongoDB" should appear in your debug toolbar.
Note that this should work with any Django application that uses PyMongo. Note that this should work with any Django application that uses PyMongo.
Obtaining stack traces can slow down queries significantly. To turn them off
add the following lines to your ``settings.py``::
DEBUG_TOOLBAR_MONGO_STACKTRACES = False
Disclaimer: only tested in latest Chrome, may fall to pieces in other browers. Disclaimer: only tested in latest Chrome, may fall to pieces in other browers.
If you feel like fixing it, contributions are welcome! If you feel like fixing it, contributions are welcome!
...@@ -28,6 +28,13 @@ inserts = [] ...@@ -28,6 +28,13 @@ inserts = []
updates = [] updates = []
removes = [] removes = []
WANT_STACK_TRACE = getattr(settings, 'DEBUG_TOOLBAR_MONGO_STACKTRACES', True)
def _get_stacktrace():
if WANT_STACK_TRACE:
return _tidy_stacktrace(reversed(inspect.stack()))
else:
return []
# Wrap Cursor._refresh for getting queries # Wrap Cursor._refresh for getting queries
@functools.wraps(_original_methods['insert']) @functools.wraps(_original_methods['insert'])
...@@ -47,7 +54,7 @@ def _insert(collection_self, doc_or_docs, manipulate=True, ...@@ -47,7 +54,7 @@ def _insert(collection_self, doc_or_docs, manipulate=True,
'document': doc_or_docs, 'document': doc_or_docs,
'safe': safe, 'safe': safe,
'time': total_time, 'time': total_time,
'stack_trace': _tidy_stacktrace(reversed(inspect.stack())), 'stack_trace': _get_stacktrace(),
}) })
return result return result
...@@ -75,7 +82,7 @@ def _update(collection_self, spec, document, upsert=False, ...@@ -75,7 +82,7 @@ def _update(collection_self, spec, document, upsert=False,
'spec': spec, 'spec': spec,
'safe': safe, 'safe': safe,
'time': total_time, 'time': total_time,
'stack_trace': _tidy_stacktrace(reversed(inspect.stack())), 'stack_trace': _get_stacktrace(),
}) })
return result return result
...@@ -96,7 +103,7 @@ def _remove(collection_self, spec_or_id, safe=False, **kwargs): ...@@ -96,7 +103,7 @@ def _remove(collection_self, spec_or_id, safe=False, **kwargs):
'spec_or_id': spec_or_id, 'spec_or_id': spec_or_id,
'safe': safe, 'safe': safe,
'time': total_time, 'time': total_time,
'stack_trace': _tidy_stacktrace(reversed(inspect.stack())), 'stack_trace': _get_stacktrace(),
}) })
return result return result
...@@ -125,7 +132,7 @@ def _cursor_refresh(cursor_self): ...@@ -125,7 +132,7 @@ def _cursor_refresh(cursor_self):
query_data = { query_data = {
'time': total_time, 'time': total_time,
'operation': 'query', 'operation': 'query',
'stack_trace': _tidy_stacktrace(reversed(inspect.stack())), 'stack_trace': _get_stacktrace(),
} }
# Collection in format <db_name>.<collection_name> # Collection in format <db_name>.<collection_name>
......
...@@ -2,7 +2,7 @@ from setuptools import setup, find_packages ...@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup( setup(
name='django-debug-toolbar-mongo', name='django-debug-toolbar-mongo',
version='0.1.2', version='0.1.3',
description='MongoDB panel for the Django Debug Toolbar', description='MongoDB panel for the Django Debug Toolbar',
long_description=open('README.rst').read(), long_description=open('README.rst').read(),
author='Harry Marr', author='Harry Marr',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment