Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add the ability to hide (costly) stacktraces

  • Loading branch information...
commit db98ef8ffe2400f13ff55f8cbed8830c3046eed9 1 parent 0e05413
@colinhowe colinhowe authored
View
5 README.rst
@@ -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.
+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.
If you feel like fixing it, contributions are welcome!
View
15 debug_toolbar_mongo/operation_tracker.py
@@ -28,6 +28,13 @@
updates = []
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
@functools.wraps(_original_methods['insert'])
@@ -47,7 +54,7 @@ def _insert(collection_self, doc_or_docs, manipulate=True,
'document': doc_or_docs,
'safe': safe,
'time': total_time,
- 'stack_trace': _tidy_stacktrace(reversed(inspect.stack())),
+ 'stack_trace': _get_stacktrace(),
})
return result
@@ -75,7 +82,7 @@ def _update(collection_self, spec, document, upsert=False,
'spec': spec,
'safe': safe,
'time': total_time,
- 'stack_trace': _tidy_stacktrace(reversed(inspect.stack())),
+ 'stack_trace': _get_stacktrace(),
})
return result
@@ -96,7 +103,7 @@ def _remove(collection_self, spec_or_id, safe=False, **kwargs):
'spec_or_id': spec_or_id,
'safe': safe,
'time': total_time,
- 'stack_trace': _tidy_stacktrace(reversed(inspect.stack())),
+ 'stack_trace': _get_stacktrace(),
})
return result
@@ -125,7 +132,7 @@ def privar(name):
query_data = {
'time': total_time,
'operation': 'query',
- 'stack_trace': _tidy_stacktrace(reversed(inspect.stack())),
+ 'stack_trace': _get_stacktrace(),
}
# Collection in format <db_name>.<collection_name>
View
2  setup.py
@@ -2,7 +2,7 @@
setup(
name='django-debug-toolbar-mongo',
- version='0.1.2',
+ version='0.1.3',
description='MongoDB panel for the Django Debug Toolbar',
long_description=open('README.rst').read(),
author='Harry Marr',
Please sign in to comment.
Something went wrong with that request. Please try again.