Skip to content

Commit

Permalink
Merge branch 'master' into dvz/clean-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Mashal-m authored Nov 1, 2023
2 parents 398c84e + 44b62ca commit 4f1503f
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions openedx/core/djangoapps/notifications/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ def send_notifications(user_ids, course_key: str, app_name, notification_type, c
sender_id = context.pop('sender_id', None)
default_web_config = get_default_values_of_preference(app_name, notification_type).get('web', False)
generated_notification_audience = []

for batch_user_ids in get_list_in_batches(user_ids, batch_size):
if ENABLE_NOTIFICATIONS_FILTERS.is_enabled(course_key):
logger.info(f'Sending notifications to {len(batch_user_ids)} users in {course_key}')
batch_user_ids = NotificationFilter().apply_filters(batch_user_ids, course_key, notification_type)
logger.info(f'After applying filters, sending notifications to {len(batch_user_ids)} users in {course_key}')

# check if what is preferences of user and make decision to send notification or not
preferences = CourseNotificationPreference.objects.filter(
user_id__in=batch_user_ids,
Expand All @@ -115,32 +121,26 @@ def send_notifications(user_ids, course_key: str, app_name, notification_type, c
if not preferences:
continue

notifications = []
for preference in preferences:
preference = update_user_preference(preference, preference.user_id, course_key)
if not (
user_id = preference.user_id
preference = update_user_preference(preference, user_id, course_key)
if (
preference and
preference.get_web_config(app_name, notification_type) and
preference.get_app_config(app_name).get('enabled', False)
):
batch_user_ids.remove(preference.user_id)
if ENABLE_NOTIFICATIONS_FILTERS.is_enabled(course_key):
logger.info(f'Sending notifications to {len(batch_user_ids)} users.')
batch_user_ids = NotificationFilter().apply_filters(batch_user_ids, course_key, notification_type)
logger.info(f'After applying filters, sending notifications to {len(batch_user_ids)} users.')

notifications = []
for user_id in batch_user_ids:
notifications.append(
Notification(
user_id=user_id,
app_name=app_name,
notification_type=notification_type,
content_context=context,
content_url=content_url,
course_id=course_key,
notifications.append(
Notification(
user_id=user_id,
app_name=app_name,
notification_type=notification_type,
content_context=context,
content_url=content_url,
course_id=course_key,
)
)
)
generated_notification_audience.append(user_id)
generated_notification_audience.append(user_id)

# send notification to users but use bulk_create
notification_objects = Notification.objects.bulk_create(notifications)
Expand All @@ -149,6 +149,8 @@ def send_notifications(user_ids, course_key: str, app_name, notification_type, c
notification_content = notification_objects[0].content

if notifications_generated:
logger.info(f'Temp: Notifications generated for {len(generated_notification_audience)} out of '
f'{len(user_ids)} users - {app_name} - {notification_type} - {course_key}.')
notification_generated_event(
generated_notification_audience, app_name, notification_type, course_key, content_url,
notification_content, sender_id=sender_id
Expand Down

0 comments on commit 4f1503f

Please sign in to comment.