mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-10 13:00:16 +02:00
stop the notification context profider from hitting the database for each menu hook
This commit is contained in:
parent
32e0621b0a
commit
1ce0dbde0e
@ -1,5 +1,10 @@
|
|||||||
from .models import Notification
|
from .models import Notification
|
||||||
|
from django.core.cache import cache
|
||||||
|
|
||||||
def user_notification_count(request):
|
def user_notification_count(request):
|
||||||
return {'notifications': len(Notification.objects.filter(user__id=request.user.id).filter(viewed=False))}
|
notification_count = cache.get("u-note:{}".format(request.user.id), -1)
|
||||||
|
if notification_count<0:
|
||||||
|
notification_count = Notification.objects.filter(user__id=request.user.id).filter(viewed=False).count()
|
||||||
|
cache.set("u-note:{}".format(request.user.id),notification_count,5)
|
||||||
|
|
||||||
|
return {'notifications': notification_count}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user