Reduce queries for user profiles.

Review Request #4824 — Created Oct. 21, 2013 and submitted

Information

Review Board
master

Reviewers

Reduce queries for user profiles.

Django's impending removal of get_profile() meant that we had to move to
our own queries for Profile. We ended up using Profile.objects.get and
get_or_create queries elsewhere, but in code paths where a profile was
accessed twice, this resulted in extraneous queries.

User.get_profile is now brought back, and it's under our control. We now
provide our own implementation of this that will survive their removal.
It's more performant in that it doesn't have to attempt an import and
some other logic to get the Profile model, since it can now use the
model directly. get_profile will cache the profile for future lookups.

Profile.objects.get_or_create is aware of the Profile cache, and will
return directly if it's set. It falls back on the standard
get_or_create, and will set the cache on the User before returning. This
means that, unlike how things used to be, subsequent get_or_create calls
will still do at most only one query.

Unit tests pass.

Saw fewer queries when doing multiple calls.

Description From Last Updated

So Django 1.5 still has get_profile, but it's deprecated. Do we want to make this conditional on whether get_profile already …

daviddavid
chipx86
david
  1. 
      
  2. reviewboard/accounts/models.py (Diff revision 2)
     
     
    Show all issues

    So Django 1.5 still has get_profile, but it's deprecated. Do we want to make this conditional on whether get_profile already exists?

    1. It's the same operation, but ours doesn't have the overhead of grabbing the configured model from the registered models list. Probably not worth having two code paths.

    2. OK, sure.

  3. 
      
david
  1. Ship It!

  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Loading...