Browse Source

Make unfavouriting async to prevent timeout errors from leaving orphaned records behind

closed-social-glitch-2
Eugen Rochko 7 years ago
parent
commit
0542773bca
3 changed files with 15 additions and 2 deletions
  1. +5
    -1
      app/controllers/api/v1/statuses_controller.rb
  2. +1
    -1
      app/views/api/oembed/show.json.rabl
  3. +9
    -0
      app/workers/unfavourite_worker.rb

+ 5
- 1
app/controllers/api/v1/statuses_controller.rb View File

@ -83,7 +83,11 @@ class Api::V1::StatusesController < ApiController
end
def unfavourite
@status = UnfavouriteService.new.call(current_user.account, Status.find(params[:id])).status.reload
@status = Status.find(params[:id])
@favourited_map = { @status.id => false }
UnfavouriteWorker.perform_async(current_user.account_id, @status.id)
render action: :show
end

+ 1
- 1
app/views/api/oembed/show.json.rabl View File

@ -11,4 +11,4 @@ node(:provider_url) { root_url }
node(:cache_age) { 86_400 }
node(:html) { |entry| "<iframe src=\"#{embed_account_stream_entry_url(entry.account, entry)}\" style=\"width: 100%; overflow: hidden\" frameborder=\"0\" width=\"#{@width}\" height=\"#{@height}\" scrolling=\"no\"></iframe>" }
node(:width) { @width }
node(:height) { nil }
node(:height) { @height }

+ 9
- 0
app/workers/unfavourite_worker.rb View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
class UnfavouriteWorker
include Sidekiq::Worker
def perform(account_id, status_id)
UnfavouriteService.new.call(Account.find(account_id), Status.find(status_id))
end
end

Loading…
Cancel
Save