Skip to content

Fix for enhancement request (Issue 27). Counting duplicate queries. #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
applying patch from issue #27.
  • Loading branch information
Vinicius Mendes committed May 30, 2010
commit 5e776d37fe72c0d7adec38cc4acdc8566196b1c0
17 changes: 16 additions & 1 deletion debug_toolbar/panels/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,28 @@ def nav_title(self):

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)
# TODO l10n: use ngettext
return "%d %s 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):
Expand Down
2 changes: 2 additions & 0 deletions debug_toolbar/templates/debug_toolbar/panels/sql.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<table>
<thead>
<tr>
<th>{% trans "Seen times" %}</th>
<th>{% trans "Time" %}&nbsp;(ms)</th>
<th>{% trans "Action" %}</th>
<th>{% trans 'Stacktrace' %}</th>
Expand All @@ -11,6 +12,7 @@
<tbody>
{% for query in queries %}
<tr class="{% cycle 'djDebugOdd' 'djDebugEven' %}">
<td>{{ query.seen }}</td>
<td>{{ query.duration|floatformat:"2" }}</td>
<td>
{% if query.params %}
Expand Down