Skip to content

Commit

Permalink
Allow to skip creating transactional emails (#2042)
Browse files Browse the repository at this point in the history
  • Loading branch information
acasajus authored Feb 27, 2024
1 parent 37f227d commit 1dada1a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,3 +567,5 @@ def getRateLimitFromConfig(
UPCLOUD_USERNAME = os.environ.get("UPCLOUD_USERNAME", None)
UPCLOUD_PASSWORD = os.environ.get("UPCLOUD_PASSWORD", None)
UPCLOUD_DB_ID = os.environ.get("UPCLOUD_DB_ID", None)

STORE_TRANSACTIONAL_EMAILS = "STORE_TRANSACTIONAL_EMAILS" in os.environ
2 changes: 1 addition & 1 deletion app/email_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ def generate_verp_email(
# Time is in minutes granularity and start counting on 2022-01-01 to reduce bytes to represent time
data = [
verp_type.value,
object_id,
object_id or 0,
int((time.time() - VERP_TIME_START) / 60),
]
json_payload = json.dumps(data).encode("utf-8")
Expand Down
14 changes: 14 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3178,6 +3178,20 @@ class TransactionalEmail(Base, ModelMixin):

__table_args__ = (sa.Index("ix_transactional_email_created_at", "created_at"),)

@classmethod
def create(cls, **kw):
# whether to call Session.commit
commit = kw.pop("commit", False)

r = cls(**kw)
if not config.STORE_TRANSACTIONAL_EMAILS:
return r

Session.add(r)
if commit:
Session.commit()
return r


class Payout(Base, ModelMixin):
"""Referral payouts"""
Expand Down

0 comments on commit 1dada1a

Please sign in to comment.