mirror of
https://github.com/discourse/discourse.git
synced 2026-08-07 13:19:19 +08:00
Pt. 2 of the performance update to group add/remove users, building on #38737 This PR moves the bulk_add/remove logic from the `Group` model into `GroupManager`, making `GroupManager` the single owner of membership mutation logic. `Group#bulk_add` and `Group#bulk_remove` become thin delegators. The controller's per-user `add_user_to_group` loop is replaced with a single bulk `add_users_to_group` call. `GroupActionLogger` gets `bulk_log_add_users_to_group` / `bulk_log_remove_users_from_group` backed by `insert_all`. `DiscourseConnect` routes through `GroupManager` instead of raw `GroupUser.create!/destroy_all` Also moves notifications for adding users to a group to a background job, as that was running synchronously and causing performance issues when `notify_users: true` There will be a Pt. 3 (#39091) that updates all callers using some variation of `GroupUser.create` and removes callbacks from `GroupUser`
16 lines
404 B
Ruby
Vendored
16 lines
404 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class NotifyUsersAddedToGroup < ::Jobs::Base
|
|
def execute(args)
|
|
user_ids = args[:user_ids]
|
|
group_id = args[:group_id]
|
|
return if group_id.blank? || user_ids.blank?
|
|
|
|
group = Group.find_by(id: group_id)
|
|
return if group.nil?
|
|
|
|
User.where(id: user_ids).find_each { |user| group.notify_added_to_group(user) }
|
|
end
|
|
end
|
|
end
|