discourse/app/jobs/regular/topic_action_converter.rb
David Taylor 3cfe086a94
FIX: Limit personal message participants when converting from topic (#9343)
Previously all topic posters would be added which could lead to major performance issues. Now if there are too many posters, only the acting user will be added as a participant.
2020-04-03 16:42:01 +01:00

21 lines
754 B
Ruby

# frozen_string_literal: true
class Jobs::TopicActionConverter < ::Jobs::Base
# Re-creating all the user actions could be very slow, so let's do it in a job
# to avoid a N+1 query on a front facing operation.
def execute(args)
topic = Topic.find_by(id: args[:topic_id])
return if topic.blank?
UserAction.where(
target_topic_id: topic.id,
action_type: [UserAction::GOT_PRIVATE_MESSAGE, UserAction::NEW_PRIVATE_MESSAGE]).find_each do |ua|
UserAction.remove_action!(ua.attributes.symbolize_keys.slice(:action_type, :user_id, :acting_user_id, :target_topic_id, :target_post_id))
end
topic.posts.find_each { |post| UserActionManager.post_created(post) }
UserActionManager.topic_created(topic)
end
end