Skip to content
Browse files

Speed up ticket query with better SQL.

  • Loading branch information...
1 parent 50c262b commit 0f027988eab6c906c194adc17e1cd2d206311d0e @mrjbq7 mrjbq7 committed
Showing with 17 additions and 15 deletions.
  1. +17 −15 tracstats/web_ui.py
View
32 tracstats/web_ui.py
@@ -145,7 +145,7 @@ def process_request(self, req):
add_stylesheet(req, 'stats/common.css')
# Include javascript libraries
- add_script(req, 'stats/jquery-1.4.3.min.js')
+ add_script(req, 'stats/jquery-1.6.3.min.js')
add_script(req, 'stats/jquery.flot.min.js')
add_script(req, 'stats/jquery.tablesorter.min.js')
add_script(req, 'stats/jquery.sparkline.min.js')
@@ -1017,14 +1017,15 @@ def _process_tickets(self, req, cursor, where, since, data):
data['byauthor'] = stats
cursor.execute("""\
- select t.component, count(distinct t.id), count(distinct open.id)
+ select t.component, count(distinct t.id), open.total
from ticket t
- join ticket open using (component)
- where (open.resolution is null or length(open.resolution) = 0) """ +
- where.replace('where',
- 'and').replace('time',
- 't.time').replace('author',
- 't.reporter')+ """
+ join (
+ select component, count(distinct id) as total
+ from ticket
+ where (resolution is null or length(resolution) = 0) """ +
+ where.replace('where', 'and').replace('author', 'reporter') + """
+ ) as open using (component) """ +
+ where.replace('time', 't.time').replace('author', 't.reporter') + """
group by 1 order by 2 desc
""")
rows = cursor.fetchall()
@@ -1037,14 +1038,15 @@ def _process_tickets(self, req, cursor, where, since, data):
data['bycomponent'] = stats
cursor.execute("""\
- select t.milestone, count(distinct t.id), count(distinct open.id)
+ select t.milestone, count(distinct t.id), open.total
from ticket t
- join ticket open using (milestone)
- where (open.resolution is null or length(open.resolution) = 0) """ +
- where.replace('where',
- 'and').replace('time',
- 't.time').replace('author',
- 't.reporter')+ """
+ join (
+ select milestone, count(distinct id) as total
+ from ticket
+ where (resolution is null or length(resolution) = 0) """ +
+ where.replace('where', 'and').replace('author', 'reporter') + """
+ ) as open using (milestone) """ +
+ where.replace('time', 't.time').replace('author', 't.reporter') + """
group by 1 order by 2 desc
""")
rows = cursor.fetchall()

0 comments on commit 0f02798

Please sign in to comment.
Something went wrong with that request. Please try again.