Class: CleanUpThreadFollowersJob

Inherits:
ApplicationJob show all
Defined in:
/var/apps/qpixel/app/jobs/clean_up_thread_followers_job.rb

Instance Method Summary collapse

Methods inherited from ApplicationJob

#exec, #initialize, #logger

Constructor Details

This class inherits a constructor from ApplicationJob

Instance Method Details

#performObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File '/var/apps/qpixel/app/jobs/clean_up_thread_followers_job.rb', line 4

def perform
  sql = File.read(Rails.root.join('db/scripts/threads_with_duplicate_followers.sql'))
  threads = ActiveRecord::Base.connection.execute(sql).to_a

  threads.each do |thread|
    user_id, thread_id = thread

    followers = ThreadFollower.where(comment_thread_id: thread_id, user_id: user_id)

    next unless followers.many?

    duplicate = followers.first
    result = duplicate.destroy

    next if result

    logger.warn "Failed to destroy thread follower duplicate \"#{duplicate.id}. Validations follow."
    duplicate.errors.full_messages.each do |msg|
      logger.warn msg
    end
  end

  logger.info "Processed #{threads.size} threads."
end