mirror of
https://github.com/discourse/discourse.git
synced 2024-12-19 10:39:01 +08:00
DEV: Memoize group find when adding users to groups (#30296)
This commit is contained in:
parent
a141a096d1
commit
537f09912e
|
@ -22,6 +22,7 @@ DiscourseAutomation::Scriptable.add(
|
||||||
|
|
||||||
# mapping of group full_names to ids for quick lookup
|
# mapping of group full_names to ids for quick lookup
|
||||||
group_ids_by_name = Group.where.not(full_name: [nil, ""]).pluck(:full_name, :id).to_h
|
group_ids_by_name = Group.where.not(full_name: [nil, ""]).pluck(:full_name, :id).to_h
|
||||||
|
groups_by_id = {}
|
||||||
|
|
||||||
# find users with the custom field who aren't in their designated group
|
# find users with the custom field who aren't in their designated group
|
||||||
User
|
User
|
||||||
|
@ -37,7 +38,7 @@ DiscourseAutomation::Scriptable.add(
|
||||||
.find_each do |user|
|
.find_each do |user|
|
||||||
next unless group_id = group_ids_by_name[user.group_name]
|
next unless group_id = group_ids_by_name[user.group_name]
|
||||||
|
|
||||||
group = Group.find(group_id)
|
group = groups_by_id[group_id] ||= Group.find(group_id)
|
||||||
group.add(user)
|
group.add(user)
|
||||||
GroupActionLogger.new(Discourse.system_user, group).log_add_user_to_group(user)
|
GroupActionLogger.new(Discourse.system_user, group).log_add_user_to_group(user)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user