Reduce database queries when returning the User list resource.
Review Request #4825 — Created Oct. 21, 2013 and submitted
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? |
david |
- Change Summary:
-
Added some comments to hopefully clarify these User model additions.
- Diff:
-
Revision 2 (+68 -25)