changeset 384:957955279a15

Fixing #188; improve number of SQL queries for mark all forums read and add the button on the view topics with unread posts view.
author Brian Neal <bgneal@gmail.com>
date Wed, 16 Mar 2011 01:49:10 +0000
parents b2b37cdd020a
children 2a03c69792d8
files gpp/forums/views/main.py gpp/templates/forums/topic_list.html
diffstat 2 files changed, 11 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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'))
 
--- 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 %}
    </tbody>
 </table>
+
+{% if unread and page.object_list %}
+<form action="{% url 'forums-catchup_all' %}" method="post">{% csrf_token %}
+   <input type="submit" value="Mark All Forums Read" />
+</form>
+<br />
+
+{% endif %}
 {{ page_nav }}
 </div>
 {% endblock %}