about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-03-16 22:59:47 +0100
committerGitHub <noreply@github.com>2019-03-16 22:59:47 +0100
commit6e3a4bcbc70bb33bfb0746cf3b2186ee9f4e6515 (patch)
tree239e6c3779ce64ee9833c3eec761ea158c2813b3 /app/services
parent6af2300454c960ef83f7b7d31e9b829e0d5a8e38 (diff)
parent8ea344fed40ae1dccf5e1b6ecfd0014128c10fb7 (diff)
Merge pull request #962 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/services')
-rw-r--r--app/services/remove_status_service.rb32
1 files changed, 21 insertions, 11 deletions
diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb
index 7eec11ddf..6e4998e07 100644
--- a/app/services/remove_status_service.rb
+++ b/app/services/remove_status_service.rb
@@ -14,17 +14,23 @@ class RemoveStatusService < BaseService
     @stream_entry = status.stream_entry
     @options      = options
 
-    remove_from_self if status.account.local?
-    remove_from_followers
-    remove_from_lists
-    remove_from_affected
-    remove_reblogs
-    remove_from_hashtags
-    remove_from_public
-    remove_from_media if status.media_attachments.any?
-    remove_from_direct if status.direct_visibility?
-
-    @status.destroy!
+    RedisLock.acquire(lock_options) do |lock|
+      if lock.acquired?
+        remove_from_self if status.account.local?
+        remove_from_followers
+        remove_from_lists
+        remove_from_affected
+        remove_reblogs
+        remove_from_hashtags
+        remove_from_public
+        remove_from_media if status.media_attachments.any?
+        remove_from_direct if status.direct_visibility?
+
+        @status.destroy!
+      else
+        raise Mastodon::RaceConditionError
+      end
+    end
 
     # There is no reason to send out Undo activities when the
     # cause is that the original object has been removed, since
@@ -164,4 +170,8 @@ class RemoveStatusService < BaseService
     end
     Redis.current.publish("timeline:direct:#{@account.id}", @payload) if @account.local?
   end
+
+  def lock_options
+    { redis: Redis.current, key: "distribute:#{@status.id}" }
+  end
 end