about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-12-19 09:12:00 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-12-19 09:12:29 +0100
commit0542773bca804868c8e4b45fe08f6041cb1b5851 (patch)
treefaced5b2e24aa89c8ab773bf9caabc0394454a95 /app
parent6b67b55cee5d3adda87b3990e54bdd7fefee1ef6 (diff)
Make unfavouriting async to prevent timeout errors from leaving orphaned records behind
Diffstat (limited to 'app')
-rw-r--r--app/controllers/api/v1/statuses_controller.rb6
-rw-r--r--app/views/api/oembed/show.json.rabl2
-rw-r--r--app/workers/unfavourite_worker.rb9
3 files changed, 15 insertions, 2 deletions
diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb
index 8b7690850..453d003da 100644
--- a/app/controllers/api/v1/statuses_controller.rb
+++ b/app/controllers/api/v1/statuses_controller.rb
@@ -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
 
diff --git a/app/views/api/oembed/show.json.rabl b/app/views/api/oembed/show.json.rabl
index f33b70ee5..311c02dad 100644
--- a/app/views/api/oembed/show.json.rabl
+++ b/app/views/api/oembed/show.json.rabl
@@ -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 }
diff --git a/app/workers/unfavourite_worker.rb b/app/workers/unfavourite_worker.rb
new file mode 100644
index 000000000..a14c82d6f
--- /dev/null
+++ b/app/workers/unfavourite_worker.rb
@@ -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