discourse/app/jobs/regular/merge_user.rb
Vinoth Kannan eb60fc86dc
PERF: run user merging task in a background job. (#10961)
* PERF: run user merging task in a background job.

Currently, admin page is timing out while merging the users with lots of posts.
2020-12-10 15:52:08 +11:00

25 lines
954 B
Ruby

# frozen_string_literal: true
module Jobs
class MergeUser < ::Jobs::Base
def execute(args)
target_user_id = args[:target_user_id]
current_user_id = args[:current_user_id]
user = User.find_by(id: args[:user_id])
target_user = User.find_by(id: args[:target_user_id])
current_user = User.find_by(id: args[:current_user_id])
guardian = Guardian.new(current_user)
serializer_opts = { root: false, scope: guardian }
if user = UserMerger.new(user, target_user, current_user).merge!
user_json = AdminDetailedUserSerializer.new(user, serializer_opts).as_json
::MessageBus.publish '/merge_user', { success: 'OK' }.merge(merged: true, user: user_json), user_ids: [current_user.id]
else
::MessageBus.publish '/merge_user', { failed: 'FAILED' }.merge(user: AdminDetailedUserSerializer.new(@user, serializer_opts).as_json), user_ids: [current_user.id]
end
end
end
end