mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
PERF: Remove N+1 query.
This commit is contained in:
parent
a98aae3bcd
commit
fc4fde453d
@ -133,9 +133,11 @@ class PostAlerter
|
|||||||
.pluck(:user_id)
|
.pluck(:user_id)
|
||||||
|
|
||||||
group_ids = topic.allowed_groups.pluck(:group_id)
|
group_ids = topic.allowed_groups.pluck(:group_id)
|
||||||
group_watchers = GroupUser.where(group_id: group_ids,
|
|
||||||
notification_level: GroupUser.notification_levels[:watching_first_post])
|
group_watchers = GroupUser.where(
|
||||||
.pluck(:user_id)
|
group_id: group_ids,
|
||||||
|
notification_level: GroupUser.notification_levels[:watching_first_post]
|
||||||
|
).pluck(:user_id)
|
||||||
|
|
||||||
watchers = [cat_watchers, tag_watchers, group_watchers].flatten
|
watchers = [cat_watchers, tag_watchers, group_watchers].flatten
|
||||||
|
|
||||||
@ -146,18 +148,15 @@ class PostAlerter
|
|||||||
|
|
||||||
def notify_first_post_watchers(post, user_ids)
|
def notify_first_post_watchers(post, user_ids)
|
||||||
return if user_ids.blank?
|
return if user_ids.blank?
|
||||||
|
|
||||||
user_ids.uniq!
|
user_ids.uniq!
|
||||||
|
|
||||||
# Don't notify the OP
|
# Don't notify the OP
|
||||||
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)
|
||||||
user_ids.each do |id|
|
|
||||||
u = User.find_by(id: id)
|
users.each do |user|
|
||||||
create_notification(u, Notification.types[:watching_first_post], post)
|
create_notification(user, Notification.types[:watching_first_post], post)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user