2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-10-02 00:01:53 -04:00
|
|
|
class Jobs::TopicActionConverter < ::Jobs::Base
|
2019-01-03 12:03:01 -05:00
|
|
|
# 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],
|
2023-01-09 07:20:10 -05:00
|
|
|
)
|
2019-01-03 12:03:01 -05:00
|
|
|
.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,
|
2023-01-09 07:20:10 -05:00
|
|
|
),
|
2019-01-03 12:03:01 -05:00
|
|
|
)
|
|
|
|
end
|
2020-04-03 11:42:01 -04:00
|
|
|
topic.posts.find_each { |post| UserActionManager.post_created(post) }
|
2019-01-03 12:03:01 -05:00
|
|
|
UserActionManager.topic_created(topic)
|
|
|
|
end
|
|
|
|
end
|