Skip to content

Commit 4b764a7

Browse files
committed
Speed app NotificationQuerySet.for_user
1 parent e832408 commit 4b764a7

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

tigaserver_app/managers.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,17 @@ def visible(self):
9393

9494
class NotificationQuerySet(models.QuerySet):
9595
def for_user(self, user: 'TigaUser'):
96-
from .models import SentNotification
96+
from .models import NotificationTopic
9797

98-
sent_notifications_subquery = SentNotification.objects.filter(
99-
notification=models.OuterRef('pk')
100-
).filter(
101-
models.Q(sent_to_user=user) |
102-
models.Q(sent_to_topic__topic_code='global') |
103-
models.Q(sent_to_topic__topic_users__user=user)
104-
).values('notification').distinct('notification')
98+
topics = NotificationTopic.objects.filter(
99+
models.Q(topic_users__user=user) | models.Q(topic_code='global')
100+
).distinct()
105101

106102
return self.filter(
107103
models.Q(user=user) |
108104
#models.Q(report__user=user) |
109-
models.Q(pk__in=models.Subquery(sent_notifications_subquery))
105+
models.Q(notification_sendings__sent_to_user=user) |
106+
models.Q(notification_sendings__sent_to_topic__in=topics)
110107
)
111108

112109
def seen_by_user(self, user: 'TigaUser', state: bool = True):

0 commit comments

Comments
 (0)