Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
117:a3633f39f3ce | 118:a20b2c492d55 |
---|---|
32 paginator = DiggPaginator(users, 10, body=5, tail=3, margin=3, padding=2) | 32 paginator = DiggPaginator(users, 10, body=5, tail=3, margin=3, padding=2) |
33 try: | 33 try: |
34 the_page = paginator.page(int(page)) | 34 the_page = paginator.page(int(page)) |
35 except InvalidPage: | 35 except InvalidPage: |
36 raise Http404 | 36 raise Http404 |
37 | |
38 # Attach user profiles to each post to avoid using get_user_profile() in | |
39 # the template. | |
40 users = set(user.id for user in the_page.object_list) | |
41 | |
42 profiles = UserProfile.objects.filter(user__id__in=users).select_related() | |
43 user_profiles = dict((profile.user.id, profile) for profile in profiles) | |
44 | |
45 for user in the_page.object_list: | |
46 user.user_profile = user_profiles[user.id] | |
37 | 47 |
38 return render_to_response('bio/members.html', { | 48 return render_to_response('bio/members.html', { |
39 'page': the_page, | 49 'page': the_page, |
40 'type': type, | 50 'type': type, |
41 }, | 51 }, |