Mercurial > public > sg101
comparison shoutbox/views.py @ 791:0ca691cccf8d
Utilize select_related() for user & user profiles.
This commit also removes the caching of the avatar URL in the
avatar template tag. This is because we are now using select_related,
so we already have the profile & avatar when we get to the tag.
Thus we don't need to waste time querying the cache.
Removed an apparently unused member map template as well.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 23 May 2014 21:52:41 -0500 |
parents | ee87ea74d46b |
children | e932f2ecd4a7 |
comparison
equal
deleted
inserted
replaced
790:6a06080e7ca8 | 791:0ca691cccf8d |
---|---|
52 context_instance = RequestContext(request)) | 52 context_instance = RequestContext(request)) |
53 | 53 |
54 | 54 |
55 def view_history(request): | 55 def view_history(request): |
56 """This view allows one to view the shoutbox history.""" | 56 """This view allows one to view the shoutbox history.""" |
57 paginator = DiggPaginator(Shout.objects.all().select_related(), | 57 qs = Shout.objects.select_related('user', 'user__profile') |
58 paginator = DiggPaginator(qs, | |
58 SHOUTS_PER_PAGE, body=5, tail=3, margin=3, padding=2) | 59 SHOUTS_PER_PAGE, body=5, tail=3, margin=3, padding=2) |
59 page = get_page(request.GET) | 60 page = get_page(request.GET) |
60 try: | 61 try: |
61 the_page = paginator.page(page) | 62 the_page = paginator.page(page) |
62 except InvalidPage: | 63 except InvalidPage: |
64 | 65 |
65 return render_to_response('shoutbox/view.html', { | 66 return render_to_response('shoutbox/view.html', { |
66 'page': the_page, | 67 'page': the_page, |
67 }, | 68 }, |
68 context_instance = RequestContext(request)) | 69 context_instance = RequestContext(request)) |
69 | 70 |
70 | 71 |
71 shout_id_re = re.compile(r'shout-(\d+)') | 72 shout_id_re = re.compile(r'shout-(\d+)') |
72 | 73 |
73 def text(request): | 74 def text(request): |
74 """This view function retrieves the text of a shout; it is used in the in-place | 75 """This view function retrieves the text of a shout; it is used in the in-place |