Drastically reduce the number of queries made in the dashboard.

Review Request #817 — Created April 14, 2009 and submitted

Information

Review Board SVN (deprecated)
trunk
406

Reviewers

Drastically reduce the number of queries made in the dashboard.

Our dashboard started out simple, with minimal queries, but as we added
new columns we introduced a number of fairly expensive queries that
operated on each review request individually. This ballooned up to a
worst case of a few hundred queries in a full dashboard. The worst
offenders are columns that are pretty common in most dashboards.

This change cleans up our queries by removing or reducing the individual
queries in most cells.

The ReviewRequest manager methods (public, to_user, etc.) now take an
optional with_counts parameter that, when True, will perform several
extra queries as part of the query for the review requests to return the
counts that we care about. This makes for a more complex query (though
not a very expensive one, especially in comparison), but reduces our
query count by 5 or so queries per review request (depending on column
configuration and such).

The query count for the New Updates column has been reduced from 4
possible queries down to 1, saving another 3 per review request.

Also, the logic for ReviewRequest.get_new_reviews was performing one
more query than it needed. It was getting the count and THEN getting the
first object. We really just wanted that first object. This may reduce
the query count for some parts of the codebase, but the dashboard no
longer uses this function.

So in total, on a full dashboard with 30 rows and all our expensive
columns, we should save upwards of 240 queries, hopefully speeding up
the dashboard quite a lot and reducing stress on the database.

 
chipx86
Review request changed

Change Summary:

Added a last_activity_timestamp field we're pulling in for the Last Updated column. This requires a small hack in the ReviewRequest model, which I'll clean up in a better way in a future change.

Bugs:

+406

Diff:

Revision 2 (+166 -85)

Show changes

david
  1. Does this need any migrations?
    1. Nope, none. We're not actually adding any new fields, just computing some extra stuff in the query.
  2. /trunk/reviewboard/reviews/managers.py (Diff revision 2)
     
     
    This can just be "if user"
  3. 
      
Loading...