prevent querying user/last_topic per row
on every forum, we were doing a query for every topic displayed, to get the user that authored the post and also a query to get the last post in the topic. this checkin knocks down the query count per page from 50 to 7
This commit is contained in:
parent
96559365b7
commit
f1c9a94816
2 changed files with 2 additions and 2 deletions
|
@ -53,7 +53,7 @@
|
|||
{% trans "Sticky:" %}
|
||||
{% endif %}
|
||||
<h3 {% if not topic|has_unreads:user %}class="topic_isread"{% endif %}>{% link topic %}</h3>
|
||||
<span class="byuser">{% trans "by" %} {{ topic.user.username }}</span>
|
||||
<span class="byuser">{% trans "by" %} {{ topic.user.username }}</span>
|
||||
{% if topic|has_unreads:user %}<a href="{{ topic|forum_unread_link:user }}">{% trans "(New Posts)" %}</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -353,7 +353,7 @@ def show_forum(request, forum_id, full=True):
|
|||
forum = get_object_or_404(Forum, pk=forum_id)
|
||||
if not forum.category.has_access(request.user):
|
||||
return HttpResponseForbidden()
|
||||
topics = forum.topics.order_by('-sticky', '-updated').select_related()
|
||||
topics = forum.topics.order_by('-sticky', '-updated').select_related('last_post__user', 'user')
|
||||
moderator = request.user.is_superuser or\
|
||||
request.user in forum.moderators.all()
|
||||
to_return = {'categories': Category.objects.all(),
|
||||
|
|
Reference in a new issue