Cache object lookups in WebAPIResource.get_object.

Review Request #5906 — Created May 30, 2014 and submitted

Information

Djblets
release-0.8.x
1e2829c...

Reviewers

It's pretty common for different parts of a WebAPIResource subclass to
perform a get_object() call either on itself or on another resource.
This will happen in get_queryset() and in the permission-checking
functions. These checks are time-consuming and result in excess
database queries.

The built-in get_object() now supports caching of these objects. The
caches are tied to the request, so any redundant get_object() calls
taking place within that request will just use the original call's
result.

Djblets and Review Board unit tests pass.

Review Board unit tests gained nearly a 2 second increase in speed for
the API tests.

Tested a few resources I suspected had redundant calls. Saw the query counts
drop.

reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        djblets/webapi/resources.py
      Ignored Files:
    
    
  2. 
      
reviewbot
  1. This is a review from Review Bot.
      Tool: Pyflakes
      Processed Files:
        djblets/webapi/resources.py
      Ignored Files:
    
    
  2. 
      
david
  1. Ship It!

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