diff gpp/bio/views.py @ 118:a20b2c492d55

Reduced some sql queries by adding a select_related and monkey patching user profiles onto a user list in shoutbox and the bio/member's list, respectively.
author Brian Neal <bgneal@gmail.com>
date Sat, 24 Oct 2009 02:39:19 +0000
parents 62eb9cbbcffc
children 903ae6168071
line wrap: on
line diff
--- a/gpp/bio/views.py	Fri Oct 23 03:09:33 2009 +0000
+++ b/gpp/bio/views.py	Sat Oct 24 02:39:19 2009 +0000
@@ -35,6 +35,16 @@
     except InvalidPage:
         raise Http404
 
+    # Attach user profiles to each post to avoid using get_user_profile() in
+    # the template.
+    users = set(user.id for user in the_page.object_list)
+
+    profiles = UserProfile.objects.filter(user__id__in=users).select_related()
+    user_profiles = dict((profile.user.id, profile) for profile in profiles)
+
+    for user in the_page.object_list:
+        user.user_profile = user_profiles[user.id]
+
     return render_to_response('bio/members.html', {
         'page': the_page,
         'type': type,