PERF: reduce memory usage for post alerter
This commit is contained in:
parent
ce815276d0
commit
060e78e884
|
@ -155,8 +155,10 @@ class PostAlerter
|
||||||
user_ids -= [post.user_id]
|
user_ids -= [post.user_id]
|
||||||
|
|
||||||
users = User.where(id: user_ids)
|
users = User.where(id: user_ids)
|
||||||
|
|
||||||
DiscourseEvent.trigger(:before_create_notifications_for_users, users, post)
|
DiscourseEvent.trigger(:before_create_notifications_for_users, users, post)
|
||||||
users.each do |u|
|
user_ids.each do |id|
|
||||||
|
u = User.find_by(id: id)
|
||||||
create_notification(u, Notification.types[:watching_first_post], post)
|
create_notification(u, Notification.types[:watching_first_post], post)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -402,14 +404,16 @@ class PostAlerter
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create the notification
|
# Create the notification
|
||||||
user.notifications.create(notification_type: type,
|
created = user.notifications.create(
|
||||||
|
notification_type: type,
|
||||||
topic_id: post.topic_id,
|
topic_id: post.topic_id,
|
||||||
post_number: post.post_number,
|
post_number: post.post_number,
|
||||||
post_action_id: opts[:post_action_id],
|
post_action_id: opts[:post_action_id],
|
||||||
data: notification_data.to_json,
|
data: notification_data.to_json,
|
||||||
skip_send_email: skip_send_email)
|
skip_send_email: skip_send_email
|
||||||
|
)
|
||||||
|
|
||||||
if !existing_notification && NOTIFIABLE_TYPES.include?(type) && !user.suspended?
|
if created.id && !existing_notification && NOTIFIABLE_TYPES.include?(type) && !user.suspended?
|
||||||
# we may have an invalid post somehow, dont blow up
|
# we may have an invalid post somehow, dont blow up
|
||||||
post_url = original_post.url rescue nil
|
post_url = original_post.url rescue nil
|
||||||
if post_url
|
if post_url
|
||||||
|
@ -428,7 +432,7 @@ class PostAlerter
|
||||||
DiscourseEvent.trigger(:post_notification_alert, user, payload)
|
DiscourseEvent.trigger(:post_notification_alert, user, payload)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
created.id ? created : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def contains_email_address?(addresses, user)
|
def contains_email_address?(addresses, user)
|
||||||
|
@ -547,7 +551,9 @@ SQL
|
||||||
notify = notify.where("id NOT IN (?)", exclude_user_ids) if exclude_user_ids.present?
|
notify = notify.where("id NOT IN (?)", exclude_user_ids) if exclude_user_ids.present?
|
||||||
|
|
||||||
DiscourseEvent.trigger(:before_create_notifications_for_users, notify, post)
|
DiscourseEvent.trigger(:before_create_notifications_for_users, notify, post)
|
||||||
notify.each do |user|
|
|
||||||
|
notify.pluck(:id).each do |user_id|
|
||||||
|
user = User.find_by(id: user_id)
|
||||||
create_notification(user, Notification.types[:posted], post)
|
create_notification(user, Notification.types[:posted], post)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue