Class: TagsCleanupJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/tags_cleanup_job.rb

Instance Method Summary collapse

Instance Method Details

#performObject


4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/jobs/tags_cleanup_job.rb', line 4

def perform
  Tag.find_each do |tag|
    tag.with_lock do
      post_ids = Post.where(id: tag.post_ids).pluck(:id) || []
      removed_ids = (tag.post_ids || []) - post_ids

      tag.update_attribute :post_ids, post_ids

      logger.info "TagsCleanupJob tag##{tag.id} removed: #{removed_ids.size}"
    end
  end
end