Reduce database queries when returning the User list resource.

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

Information

Review Board
master

Reviewers

Reduce database queries when returning the User list resource.

The User API resource checked profile.is_private on each User being
serialized in a list, which is expensive. Unfortunately, neither
select_related() nor prefetch_related() appear to properly cache reverse
ForeignKey relations, so they don't help us with this.

The best solution, it seems, is to tack on an extra query for our users,
storing the result of Profile.is_private on the User. The
is_profile_visible function checks for this, and attempts to do the
right thing by making use of that value, if it's available.

Viewed the query count and list of queries before and after this change.
Before the change, there was an extra query per listed user. After,
there was a flat amount of 4 (which includes session and auth queries).

Description From Last Updated

I am really confused about the nature of 'self'. Is it a Profile or a User?

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

    I am really confused about the nature of 'self'. Is it a Profile or a User?

    1. It's the user. 'is_private' comes from the query mentioned in the comment.

    2. Can you add a comment saying that this methods is patched into the User object?

  3. 
      
chipx86
david
  1. Ship It!

  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Loading...