comparison 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
comparison
equal deleted inserted replaced
383:b2b37cdd020a 384:957955279a15
742 @require_POST 742 @require_POST
743 def catchup_all(request): 743 def catchup_all(request):
744 """ 744 """
745 This view marks all forums as being read. 745 This view marks all forums as being read.
746 """ 746 """
747 forums = Forum.objects.forums_for_user(request.user) 747 forum_ids = Forum.objects.forum_ids_for_user(request.user)
748 forum_dict = dict((forum.id, forum) for forum in forums)
749 forum_ids = forum_dict.keys()
750 748
751 tlvs = TopicLastVisit.objects.filter(user=request.user, 749 tlvs = TopicLastVisit.objects.filter(user=request.user,
752 topic__forum__id__in=forum_ids).delete() 750 topic__forum__id__in=forum_ids).delete()
753 751
754 flvs = ForumLastVisit.objects.filter(user=request.user,
755 forum__id__in=forum_ids).select_related('forum')
756
757 flv_dict = dict((flv.forum.id, flv) for flv in flvs)
758
759 now = datetime.datetime.now() 752 now = datetime.datetime.now()
760 for forum in forums: 753 ForumLastVisit.objects.filter(user=request.user,
761 flv = flv_dict.get(forum.id) 754 forum__in=forum_ids).update(begin_date=now, end_date=now)
762 if flv is None:
763 flv = ForumLastVisit(user=request.user, forum=forum)
764
765 flv.begin_date = now
766 flv.end_date = now
767 flv.save()
768 755
769 return HttpResponseRedirect(reverse('forums-index')) 756 return HttpResponseRedirect(reverse('forums-index'))
770 757
771 758
772 @login_required 759 @login_required