Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #113

Merged
merged 1 commit into from
Dec 17, 2024
Merged

Fixes #113

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions apps/subscription/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ def generate_user_alert_subscription_email_context(
email_frequency: UserAlertSubscription.EmailFrequency,
) -> tuple[bool, dict, models.QuerySet[UserAlertSubscription]]:
# NOTE: Number of subscription is static and less than UserAlertSubscription.LIMIT_PER_USER
subscription_qs = UserAlertSubscription.objects.filter(is_active=True, user=user, email_frequency=email_frequency)
subscription_qs = UserAlertSubscription.objects.filter(
is_active=True,
send_email=True,
email_frequency=email_frequency,
user=user,
)

if email_frequency == UserAlertSubscription.EmailFrequency.DAILY:
from_datetime_threshold = timezone.now() - timedelta(hours=24)
Expand Down Expand Up @@ -104,7 +109,11 @@ def send_user_alert_subscription_email(user: User, email_frequency: UserAlertSub
def send_user_alert_subscriptions_email(email_frequency: UserAlertSubscription.EmailFrequency):
# TODO: Send in parallel if email service supports it?
users_qs = User.objects.filter(
id__in=UserAlertSubscription.objects.filter(is_active=True, email_frequency=email_frequency).values('user'),
id__in=UserAlertSubscription.objects.filter(
is_active=True,
send_email=True,
email_frequency=email_frequency,
).values('user'),
)

for user in users_qs.iterator():
Expand Down
Loading