Skip to content

Commit

Permalink
Reducing DB access
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbyt3r committed Jul 13, 2023
1 parent 901bb67 commit 725e116
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions uber/tasks/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ def send_automated_emails():
quantity_sent += 1
else:
unapproved_count += 1
if datetime.now() - automated_email.last_send_time > (expiration / 2):
automated_email.last_send_time = datetime.now()
session.add(automated_email)
session.commit()

automated_email.unapproved_count = unapproved_count
automated_email.currently_sending = False
session.add(automated_email)
session.commit()
if datetime.now() - automated_email.last_send_time > (expiration / 2):
automated_email.last_send_time = datetime.now()
session.add(automated_email)
session.commit()

automated_email.unapproved_count = unapproved_count
automated_email.currently_sending = False
session.add(automated_email)
session.commit()

log.info("Sent " + str(quantity_sent) + " emails in " + str(time() - start_time) + " seconds")
return {e.ident: e.unapproved_count for e in active_automated_emails if e.unapproved_count > 0}
Expand Down

0 comments on commit 725e116

Please sign in to comment.