]> cat aescling's git repositories - mastodon.git/commitdiff
Make unfavouriting async to prevent timeout errors from leaving orphaned records...
authorEugen Rochko <eugen@zeonfederated.com>
Mon, 19 Dec 2016 08:12:00 +0000 (09:12 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Mon, 19 Dec 2016 08:12:29 +0000 (09:12 +0100)
app/controllers/api/v1/statuses_controller.rb
app/views/api/oembed/show.json.rabl
app/workers/unfavourite_worker.rb [new file with mode: 0644]

index 8b7690850fe1deed9f05e457b677b62ba046c36f..453d003da232b65f4d04b50e03b2d694f7159504 100644 (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
 
index f33b70ee5f7c6ad2eb8e5010cca403b97be98612..311c02dadd74f658789090ad8ad4fefb5244399b 100644 (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 }
diff --git a/app/workers/unfavourite_worker.rb b/app/workers/unfavourite_worker.rb
new file mode 100644 (file)
index 0000000..a14c82d
--- /dev/null
@@ -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