discourse/app/jobs/regular/topic_action_converter.rb
Krzysztof Kotlarek 427d54b2b0 DEV: Upgrading Discourse to Zeitwerk (#8098)
Zeitwerk simplifies working with dependencies in dev and makes it easier reloading class chains. 

We no longer need to use Rails "require_dependency" anywhere and instead can just use standard 
Ruby patterns to require files.

This is a far reaching change and we expect some followups here.
2019-10-02 14:01:53 +10:00

21 lines
749 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.each { |post| UserActionManager.post_created(post) }
UserActionManager.topic_created(topic)
end
end