aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/toolbar/loader.py
diff options
context:
space:
mode:
authorAymeric Augustin2013-11-09 19:07:38 +0100
committerAymeric Augustin2013-11-10 10:39:42 +0100
commit2816c6fa2a1613e5eeb7967cde0793019ce62feb (patch)
tree2aaff3c512dd78f9686a81f626cba9702a3bd157 /debug_toolbar/toolbar/loader.py
parent631bbd18c10f572e31ef30f4dc78df942beeffd4 (diff)
downloaddjango-debug-toolbar-2816c6fa2a1613e5eeb7967cde0793019ce62feb.tar.bz2
Load the content of panels dynamically.
This should drastically reduce the overhead of the browser toolbar when a page has a complex template structure or many SQL queries. This change is backwards-incompatible for third-party panels because it changes the signature of __init__. The JavaScript could probably be improved; I'm outside my comfort zone.
Diffstat (limited to 'debug_toolbar/toolbar/loader.py')
-rw-r--r--debug_toolbar/toolbar/loader.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/debug_toolbar/toolbar/loader.py b/debug_toolbar/toolbar/loader.py
index 7b525b6..de4aa93 100644
--- a/debug_toolbar/toolbar/loader.py
+++ b/debug_toolbar/toolbar/loader.py
@@ -46,7 +46,6 @@ class DebugToolbar(object):
global panel_classes
for panel_class in panel_classes:
panel_instance = panel_class(self, context=self.template_context)
-
self._panels[panel_class] = panel_instance
def render_toolbar(self):
@@ -56,8 +55,8 @@ class DebugToolbar(object):
context = self.template_context.copy()
context.update({
'panels': self.panels,
+ 'toolbar_id': save_toolbar(self),
})
-
return render_to_string('debug_toolbar/base.html', context)
@@ -101,3 +100,23 @@ def load_panel_classes():
'Toolbar Panel module "%s" does not define a "%s" class' %
(panel_module, panel_classname))
panel_classes.append(panel_class)
+
+
+toolbar_counter = 0
+toolbar_maxsize = 10 # keep data for the last 10 requests
+toolbar_results = SortedDict()
+
+
+def save_toolbar(toolbar):
+ global toolbar_counter, toolbar_results
+ toolbar_counter += 1
+ toolbar_results[toolbar_counter] = toolbar
+ for _ in range(len(toolbar_results) - toolbar_maxsize):
+ # When we drop support for Python 2.6 and switch to
+ # collections.OrderedDict, use popitem(last=False).
+ del toolbar_results[toolbar_results.keyOrder[0]]
+ return toolbar_counter
+
+
+def get_saved_toolbar(toolbar_id):
+ return toolbar_results.get(toolbar_id)