core: improve performances on notification reads and display

This commit is contained in:
2019-09-09 00:45:08 +02:00
parent eb9821ed36
commit f1b3a174b6
3 changed files with 24 additions and 2 deletions

View File

@ -2,6 +2,7 @@
#
# Copyright 2016,2017
# - Skia <skia@libskia.so>
# - Sli <antoine@bartuccio.fr>
#
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
# http://ae.utbm.fr.
@ -50,8 +51,9 @@ class NotificationList(ListView):
template_name = "core/notification_list.jinja"
def get_queryset(self):
# TODO: Bulk update in django 2.2
if "see_all" in self.request.GET.keys():
for n in self.request.user.notifications.all():
for n in self.request.user.notifications.filter(viewed=False):
n.viewed = True
n.save()
return self.request.user.notifications.order_by("-date")[:20]