Mercurial > public > sg101
diff gpp/forums/views/main.py @ 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 | a1b03de20345 |
children | c374bfd5594f |
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'))