* Enable new Rails/* cops and use autocorrect on them * Fixed Rails/PluckInWhere leftovers * Fix Rails/DefaultScope * Enable and fix Rails/PluckId * Fix manual mistake with forcing autocorrection on Rails/PluckId * Apply PR feedback to remove Rails/PluckId inline disables * Apply PR feedback to get rid of Rails/PluckInWhere inline
28 lines
900 B
Ruby
28 lines
900 B
Ruby
module Users
|
|
class MergeSyncWorker
|
|
include Sidekiq::Worker
|
|
|
|
sidekiq_options queue: :high_priority, retry: 10
|
|
|
|
def perform(user_id)
|
|
user = User.find_by(id: user_id)
|
|
return unless user
|
|
|
|
# [@practicaldev/sre]: These saves will do a lot of duplicate work. Since we are not merging users
|
|
# a lot I think this is fine for now and can be optimized in the future when we
|
|
# decrease our dependency on callbacks.
|
|
resave_content(user.articles)
|
|
resave_content(user.comments)
|
|
resave_content(user.reactions.readinglist)
|
|
resave_content(Reaction.for_articles(user.articles.ids).readinglist)
|
|
end
|
|
|
|
private
|
|
|
|
def resave_content(content_ar_relation)
|
|
# Triggers callbacks to ensure caches are busted, scores updated, and docs
|
|
# are reindexed with the correct new user
|
|
content_ar_relation.find_each(&:save)
|
|
end
|
|
end
|
|
end
|