Skip to content

Commit a842e19

Browse files
committed
Moved some code and tweaked settings to ignore sql debug functions when calculating code coverage.
- Legacy-Id: 12070
1 parent e3a7d47 commit a842e19

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from django import template
2+
3+
register = template.Library()
4+
5+
@register.filter(name='timesum')
6+
def timesum(value):
7+
"""
8+
Sum the times in a list of dicts; used for sql query debugging info"""
9+
sum = 0.0
10+
for v in value:
11+
sum += float(v['time'])
12+
return sum
13+
14+
15+
@register.filter()
16+
def expand_comma(value):
17+
"""
18+
Adds a space after each comma, to allow word-wrapping of
19+
long comma-separated lists."""
20+
return value.replace(",", ", ")
21+
22+
23+
@register.filter()
24+
def annotate_sql_queries(queries):
25+
counts = {}
26+
timeacc = {}
27+
for q in queries:
28+
sql = q['sql']
29+
if not sql in counts:
30+
counts[sql] = 0;
31+
counts[sql] += 1
32+
if not sql in timeacc:
33+
timeacc[sql] = 0.0;
34+
timeacc[sql] += float(q['time'])
35+
for q in queries:
36+
sql = q['sql']
37+
q['count'] = str(counts[sql])
38+
q['time_accum'] = "%4.3f" % timeacc[sql]
39+
return queries

0 commit comments

Comments
 (0)