Class: Jobs::TopicActionConverter

Inherits:
Base
  • Object
show all
Defined in:
app/jobs/regular/topic_action_converter.rb

Instance Method Summary collapse

Methods inherited from Base

acquire_cluster_concurrency_lock!, clear_cluster_concurrency_lock!, cluster_concurrency, cluster_concurrency_redis_key, delayed_perform, #error_context, get_cluster_concurrency, #last_db_duration, #log, #perform, #perform_immediately

Instance Method Details

#execute(args) ⇒ Object

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.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/jobs/regular/topic_action_converter.rb', line 6

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