PERF: Update UserDestroyer to fetch histories and actions in batch (#16316)

This is much more memory-efficient when there are 1000s of rows
This commit is contained in:
David Taylor 2022-03-29 16:56:55 +01:00 committed by GitHub
parent 58d6e4e233
commit 7a284164ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -40,14 +40,14 @@ class UserDestroyer
delete_posts(user, category_topic_ids, opts) delete_posts(user, category_topic_ids, opts)
end end
user.post_actions.each do |post_action| user.post_actions.find_each do |post_action|
post_action.remove_act!(Discourse.system_user) post_action.remove_act!(Discourse.system_user)
end end
# Add info about the user to staff action logs # Add info about the user to staff action logs
UserHistory.staff_action_records( UserHistory.staff_action_records(
Discourse.system_user, acting_user: user.username Discourse.system_user, acting_user: user.username
).each do |log| ).find_each do |log|
log.details ||= '' log.details ||= ''
log.details = (log.details.split("\n") + log.details = (log.details.split("\n") +
["user_id: #{user.id}", "username: #{user.username}"] ["user_id: #{user.id}", "username: #{user.username}"]