Mercurial > public > sg101
comparison gpp/forums/views/main.py @ 328:3f9b9fd54b01
Some optimizations to reduce database query times.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 22 Feb 2011 05:40:29 +0000 |
parents | c550933ff5b6 |
children | 000c006fee97 |
comparison
equal
deleted
inserted
replaced
327:a1bf6cf49720 | 328:3f9b9fd54b01 |
---|---|
125 'name': '%s Forum' % forum.name, | 125 'name': '%s Forum' % forum.name, |
126 'feed': FORUM_FEED % forum.slug, | 126 'feed': FORUM_FEED % forum.slug, |
127 } | 127 } |
128 | 128 |
129 topics = forum.topics.select_related('user', 'last_post', 'last_post__user') | 129 topics = forum.topics.select_related('user', 'last_post', 'last_post__user') |
130 get_topic_unread_status(forum, topics, request.user) | |
131 | |
132 paginator = create_topic_paginator(topics) | 130 paginator = create_topic_paginator(topics) |
133 page_num = get_page_num(request) | 131 page_num = get_page_num(request) |
134 try: | 132 try: |
135 page = paginator.page(page_num) | 133 page = paginator.page(page_num) |
136 except InvalidPage: | 134 except InvalidPage: |
137 raise Http404 | 135 raise Http404 |
138 | 136 |
137 get_topic_unread_status(forum, page.object_list, request.user) | |
139 attach_topic_page_ranges(page.object_list) | 138 attach_topic_page_ranges(page.object_list) |
140 | 139 |
141 # we do this for the template since it is rendered twice | 140 # we do this for the template since it is rendered twice |
142 page_nav = render_to_string('forums/pagination.html', {'page': page}) | 141 page_nav = render_to_string('forums/pagination.html', {'page': page}) |
143 | 142 |
164 return HttpResponseForbidden() | 163 return HttpResponseForbidden() |
165 | 164 |
166 topic.view_count = F('view_count') + 1 | 165 topic.view_count = F('view_count') + 1 |
167 topic.save(force_update=True) | 166 topic.save(force_update=True) |
168 | 167 |
169 posts = topic.posts.select_related() | 168 posts = topic.posts.select_related(depth=1) |
170 | 169 |
171 paginator = create_post_paginator(posts) | 170 paginator = create_post_paginator(posts) |
172 page_num = get_page_num(request) | 171 page_num = get_page_num(request) |
173 try: | 172 try: |
174 page = paginator.page(page_num) | 173 page = paginator.page(page_num) |