From 631bbd18c10f572e31ef30f4dc78df942beeffd4 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 9 Nov 2013 19:05:27 +0100 Subject: Avoid some implicit global lookups. They made it impossible to preserve panel data after the end of a request. --- debug_toolbar/toolbar/loader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'debug_toolbar/toolbar/loader.py') diff --git a/debug_toolbar/toolbar/loader.py b/debug_toolbar/toolbar/loader.py index c8630a9..7b525b6 100644 --- a/debug_toolbar/toolbar/loader.py +++ b/debug_toolbar/toolbar/loader.py @@ -45,7 +45,7 @@ class DebugToolbar(object): """ global panel_classes for panel_class in panel_classes: - panel_instance = panel_class(context=self.template_context) + panel_instance = panel_class(self, context=self.template_context) self._panels[panel_class] = panel_instance -- cgit v1.2.3 From 2816c6fa2a1613e5eeb7967cde0793019ce62feb Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 9 Nov 2013 19:07:38 +0100 Subject: 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. --- debug_toolbar/toolbar/loader.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'debug_toolbar/toolbar/loader.py') 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) -- cgit v1.2.3