Further optimize the Dashboard queries.

Review Request #1849 — Created Oct. 19, 2010 and submitted

Information

Review Board
master

Reviewers

Further optimize the Dashboard queries.

This solves some of the remaining problems in the dashboard. There were more
queries going on than there should have been.

Despite using the CounterField for the group counts, we still iterated over
the groups in dashboard.html, causing a redundant query. On top of that, we'd
perform a query to check if there are any starred groups, and then another
query to iterate over them. That's a total of four queries to get the
information we need.

Now, we query the joined groups and the starred groups in the query counts,
and just iterate over those values. This drops it back down to two.

If the Repository column was active, every unique repository would have a
query made to get the name, which would also bring in all other information
on the repository. We now have a RepositoryColumn class that augments the
queryset to grab the repository in the initial query. This reduces the
query count by the number of unique repositories used in the review requests
in the dashboard (at least 1, if there are any review requests at all).

This is a minimum savings of 3 queries, but likely more in most installations.
Verified through profiler output that I had reduced the query count by what I
expected given my repository and watched group counts. Also verified that the
queries we used for that information are no longer performed.
david
  1. 
      
  2. reviewboard/reviews/templatetags/reviewtags.py (Diff revision 1)
     
     
     
     
    Can you put the whole thing in parentheses to avoid the continuation symbol?
  3.