mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-12-24 06:06:49 +00:00
Reduce chances of race conditions when processing deleted toots (#9815)
* Reduce chances of race conditions when processing deleted toots * Prevent race condition when processing deleted toots
This commit is contained in:
parent
5363c724fc
commit
a4f07bad95
|
@ -5,10 +5,12 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
CONVERTED_TYPES = %w(Image Video Article Page).freeze
|
||||
|
||||
def perform
|
||||
return if delete_arrived_first?(object_uri) || unsupported_object_type? || invalid_origin?(@object['id'])
|
||||
return if unsupported_object_type? || invalid_origin?(@object['id'])
|
||||
|
||||
RedisLock.acquire(lock_options) do |lock|
|
||||
if lock.acquired?
|
||||
return if delete_arrived_first?(object_uri)
|
||||
|
||||
@status = find_existing_status
|
||||
|
||||
if @status.nil?
|
||||
|
|
|
@ -21,11 +21,13 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity
|
|||
def delete_note
|
||||
return if object_uri.nil?
|
||||
|
||||
RedisLock.acquire(lock_options) do |_lock|
|
||||
delete_later!(object_uri)
|
||||
end
|
||||
|
||||
@status = Status.find_by(uri: object_uri, account: @account)
|
||||
@status ||= Status.find_by(uri: @object['atomUri'], account: @account) if @object.is_a?(Hash) && @object['atomUri'].present?
|
||||
|
||||
delete_later!(object_uri)
|
||||
|
||||
return if @status.nil?
|
||||
|
||||
if @status.public_visibility? || @status.unlisted_visibility?
|
||||
|
@ -68,4 +70,8 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity
|
|||
def payload
|
||||
@payload ||= Oj.dump(@json)
|
||||
end
|
||||
|
||||
def lock_options
|
||||
{ redis: Redis.current, key: "create:#{object_uri}" }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue