# HG changeset patch # User Brian Neal # Date 1300240150 0 # Node ID 957955279a15226f09166869e92df226c05c65ce # Parent b2b37cdd020aa1eb033e53c7f4651d75dd42908c Fixing #188; improve number of SQL queries for mark all forums read and add the button on the view topics with unread posts view. diff -r b2b37cdd020a -r 957955279a15 gpp/forums/views/main.py --- a/gpp/forums/views/main.py Wed Mar 16 01:19:45 2011 +0000 +++ b/gpp/forums/views/main.py Wed Mar 16 01:49:10 2011 +0000 @@ -744,27 +744,14 @@ """ This view marks all forums as being read. """ - forums = Forum.objects.forums_for_user(request.user) - forum_dict = dict((forum.id, forum) for forum in forums) - forum_ids = forum_dict.keys() + forum_ids = Forum.objects.forum_ids_for_user(request.user) tlvs = TopicLastVisit.objects.filter(user=request.user, topic__forum__id__in=forum_ids).delete() - flvs = ForumLastVisit.objects.filter(user=request.user, - forum__id__in=forum_ids).select_related('forum') - - flv_dict = dict((flv.forum.id, flv) for flv in flvs) - now = datetime.datetime.now() - for forum in forums: - flv = flv_dict.get(forum.id) - if flv is None: - flv = ForumLastVisit(user=request.user, forum=forum) - - flv.begin_date = now - flv.end_date = now - flv.save() + ForumLastVisit.objects.filter(user=request.user, + forum__in=forum_ids).update(begin_date=now, end_date=now) return HttpResponseRedirect(reverse('forums-index')) diff -r b2b37cdd020a -r 957955279a15 gpp/templates/forums/topic_list.html --- a/gpp/templates/forums/topic_list.html Wed Mar 16 01:19:45 2011 +0000 +++ b/gpp/templates/forums/topic_list.html Wed Mar 16 01:49:10 2011 +0000 @@ -54,6 +54,14 @@ {% endfor %} + +{% if unread and page.object_list %} +
{% csrf_token %} + +
+
+ +{% endif %} {{ page_nav }} {% endblock %}