Only send a maximum of 20 interest emails

This commit is contained in:
Tanner Collin 2023-01-20 17:47:01 +00:00
parent 32585495be
commit 5f302a0de7

View File

@ -314,11 +314,12 @@ class SessionViewSet(Base, List, Retrieve, Create, Update):
logging.info('Session is in the past or too soon, not sending interest emails.')
return
with transaction.atomic():
interests = models.Interest.objects.filter(
course=session.course,
satisfied_by__isnull=True,
user__member__paused_date__isnull=True
)
)[:20]
for num, interest in enumerate(interests):
msg = 'Sending email {} / {}...'.format(num+1, len(interests))
@ -331,7 +332,9 @@ class SessionViewSet(Base, List, Retrieve, Create, Update):
logger.exception(msg)
utils.alert_tanner(msg)
num_satisfied = interests.update(satisfied_by=session)
interest_ids = interests.values('id')
num_satisfied = models.Interest.objects.filter(id__in=interest_ids).update(satisfied_by=session)
logging.info('Satisfied %s interests.', num_satisfied)
def generate_ical(self, session):