From 9eba139ec4e7a0d43d563cdf73b3c041f9dd733a Mon Sep 17 00:00:00 2001 From: KlemenSpruk Date: Fri, 27 Oct 2023 14:16:06 +0200 Subject: [PATCH] removed 2 queries --- .../notifications/base/channels/channel.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/django_project_base/notifications/base/channels/channel.py b/django_project_base/notifications/base/channels/channel.py index f2fc7439..40ff847f 100644 --- a/django_project_base/notifications/base/channels/channel.py +++ b/django_project_base/notifications/base/channels/channel.py @@ -128,15 +128,17 @@ def _make_send(self, notification_obj, rec_obj, message_str, dlr_pk) -> Tuple[Op sent = False logger = logging.getLogger("django") try: - dlr_exists = DeliveryReport.objects.filter( - notification=notification_obj, - user_id=rec_obj.identifier, - channel=f"{self.__module__}.{self.__class__.__name__}", - provider=f"{self.provider.__module__}.{self.provider.__class__.__name__}", + dlr_exists = list( + DeliveryReport.objects.filter( + notification=notification_obj, + user_id=rec_obj.identifier, + channel=f"{self.__module__}.{self.__class__.__name__}", + provider=f"{self.provider.__module__}.{self.provider.__class__.__name__}", + ) ) - if dlr_exists.count() > 1: + if len(dlr_exists) > 1: raise Exception(f"{gettext('To many DLR exist.')} {notification_obj} {rec_obj}") - if dlr_notification := dlr_exists.first(): + if dlr_notification := next(iter(dlr_exists), None): dlr_pk = str(dlr_notification.pk) if dlr_notification.status == DeliveryReport.Status.DELIVERED: do_send = False