MissedMessageWorker: Remove unnecessary transaction.atomic.

We only have one query which will change database state in this function,
and we already have a lock on the process itself, so there's no need for
a transaction.

This was added in ebb4eab0f9.
This commit is contained in:
Abhijeet Prasad Bodas 2021-07-21 15:31:12 +05:30 committed by Tim Abbott
parent 60e3429da3
commit de78b015d9
1 changed files with 16 additions and 17 deletions

View File

@ -587,24 +587,23 @@ class MissedMessageWorker(QueueProcessingWorker):
user_profile_id: int = event["user_profile_id"]
batch_duration = datetime.timedelta(seconds=self.BATCH_DURATION)
with transaction.atomic():
try:
pending_email = ScheduledMessageNotificationEmail.objects.filter(
user_profile_id=user_profile_id
)[0]
scheduled_timestamp = pending_email.scheduled_timestamp
except IndexError:
scheduled_timestamp = timezone_now() + batch_duration
try:
pending_email = ScheduledMessageNotificationEmail.objects.filter(
user_profile_id=user_profile_id
)[0]
scheduled_timestamp = pending_email.scheduled_timestamp
except IndexError:
scheduled_timestamp = timezone_now() + batch_duration
entry = ScheduledMessageNotificationEmail(
user_profile_id=user_profile_id,
message_id=event["message_id"],
trigger=event["trigger"],
scheduled_timestamp=scheduled_timestamp,
)
if "mentioned_user_group_id" in event:
entry.mentioned_user_group_id = event["mentioned_user_group_id"]
entry.save()
entry = ScheduledMessageNotificationEmail(
user_profile_id=user_profile_id,
message_id=event["message_id"],
trigger=event["trigger"],
scheduled_timestamp=scheduled_timestamp,
)
if "mentioned_user_group_id" in event:
entry.mentioned_user_group_id = event["mentioned_user_group_id"]
entry.save()
self.ensure_timer()