From d26b8f3cceca458b4880c090c60c9382e48ecf27 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 29 Nov 2016 15:32:25 +0100 Subject: [PATCH] Delete statuses asynchronously but provide instant feedback in the API --- app/controllers/api/v1/statuses_controller.rb | 10 +++++++--- app/workers/removal_worker.rb | 9 +++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 app/workers/removal_worker.rb diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index a693ce00d8..a0b15cfbc9 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -58,7 +58,7 @@ class Api::V1::StatusesController < ApiController def destroy @status = Status.where(account_id: current_user.account).find(params[:id]) - RemoveStatusService.new.call(@status) + RemovalWorker.perform_async(@status.id) render_empty end @@ -68,8 +68,12 @@ class Api::V1::StatusesController < ApiController end def unreblog - RemoveStatusService.new.call(Status.where(account_id: current_user.account, reblog_of_id: params[:id]).first!) - @status = Status.find(params[:id]) + reblog = Status.where(account_id: current_user.account, reblog_of_id: params[:id]).first! + @status = reblog.reblog + @reblogged_map = { @status.id => false } + + RemovalWorker.perform_async(reblog.id) + render action: :show end diff --git a/app/workers/removal_worker.rb b/app/workers/removal_worker.rb new file mode 100644 index 0000000000..7470c54f56 --- /dev/null +++ b/app/workers/removal_worker.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class RemovalWorker + include Sidekiq::Worker + + def perform(status_id) + RemoveStatusService.new.call(Status.find(status_id)) + end +end \ No newline at end of file