Reduce query counts when querying API resources.

Review Request #6411 — Created Oct. 6, 2014 and submitted

Information

Djblets
master
780dbad...

Reviewers

We previously introduced a prefetch_related() optimization for list
resources, helping to get the query counts down for any referenced
ManyToManyFields.

We also had a select_related() call, but this wasn't good enough.
Calling select_related() without parameters will only operate on
ForeignKeys that don't allow for NULL values.

Now, we build a list of fields to explicitly pass to select_related().
This has the benefit of working with fields that allow NULL values, and
prevents looking up fields we're not going to return in the payload.

Primarily tested with /api/review-requests/. When spanning pages, we
had a query count of 27 prior to this change (factoring in only the
queries that were part of the API payload, and not ones like the session
or siteconfig).

After this change, that was down to 6 (1 for the main query, 1 for total
numbers of items, 4 for the relations).

Description From Last Updated

Col: 33 E127 continuation line over-indented for visual indent

reviewbotreviewbot
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/webapi/resources.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/resources.py
    
    
  2. djblets/webapi/resources.py (Diff revision 1)
     
     
    Show all issues
    Col: 33
     E127 continuation line over-indented for visual indent
    
  3. 
      
chipx86
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/webapi/resources.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/resources.py
    
    
  2. 
      
david
  1. Ship It!

  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-0.8.x (5b5cdf6)