Skip to content

Commit

Permalink
removed 2 queries
Browse files Browse the repository at this point in the history
  • Loading branch information
KlemenSpruk committed Oct 27, 2023
1 parent 0017b42 commit 9eba139
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions django_project_base/notifications/base/channels/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9eba139

Please sign in to comment.