diff --git debug_toolbar panels sql py debug_toolbar panels sql py ind

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py
index 0c9bc61..b940da6 100644
--- a/debug_toolbar/panels/sql.py
+++ b/debug_toolbar/panels/sql.py
@@ -126,18 +126,33 @@ class SQLDebugPanel(DebugPanel):
self._offset = len(connection.queries)
self._sql_time = 0
self._queries = []
-
+
def nav_title(self):
return 'SQL'
def nav_subtitle(self):
self._queries = connection.queries[self._offset:]
+
+ self._duplicate_sql_time = 0
+ self.seen = {}
+ self.duplicate = 0
+ for q in self._queries:
+ sql = q["sql"]
+ c = self.seen.get(sql, 0)
+ if c:
+ self.duplicate += 1
+ self._duplicate_sql_time += q['duration']
+ q["seen"] = c
+ self.seen[sql]= c + 1
+
self._sql_time = sum([q['duration'] for q in self._queries])
num_queries = len(self._queries)
- return "%d %s in %.2fms" % (
+ return "%d %s in %.2fms (%d duplicate in %.2fms)" % (
num_queries,
(num_queries == 1) and 'query' or 'queries',
- self._sql_time
+ self._sql_time,
+ self.duplicate,
+ self._duplicate_sql_time,
)
def title(self):