Reduce query counts when querying API resources.

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

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).

    Loading...