Fix to add RedisLock to handle Announce activity (#14365)
This commit is contained in:
parent
0ab97107c7
commit
fcb3f259e5
1 changed files with 25 additions and 14 deletions
|
@ -4,15 +4,17 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity
|
||||||
def perform
|
def perform
|
||||||
return reject_payload! if delete_arrived_first?(@json['id']) || !related_to_local_activity?
|
return reject_payload! if delete_arrived_first?(@json['id']) || !related_to_local_activity?
|
||||||
|
|
||||||
|
RedisLock.acquire(lock_options) do |lock|
|
||||||
|
if lock.acquired?
|
||||||
original_status = status_from_object
|
original_status = status_from_object
|
||||||
|
|
||||||
return reject_payload! if original_status.nil? || !announceable?(original_status)
|
return reject_payload! if original_status.nil? || !announceable?(original_status)
|
||||||
|
|
||||||
status = Status.find_by(account: @account, reblog: original_status)
|
@status = Status.find_by(account: @account, reblog: original_status)
|
||||||
|
|
||||||
return status unless status.nil?
|
return @status unless @status.nil?
|
||||||
|
|
||||||
status = Status.create!(
|
@status = Status.create!(
|
||||||
account: @account,
|
account: @account,
|
||||||
reblog: original_status,
|
reblog: original_status,
|
||||||
uri: @json['id'],
|
uri: @json['id'],
|
||||||
|
@ -21,8 +23,13 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity
|
||||||
visibility: visibility_from_audience
|
visibility: visibility_from_audience
|
||||||
)
|
)
|
||||||
|
|
||||||
distribute(status)
|
distribute(@status)
|
||||||
status
|
else
|
||||||
|
raise Mastodon::RaceConditionError
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@status
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -54,4 +61,8 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity
|
||||||
def reblog_of_local_status?
|
def reblog_of_local_status?
|
||||||
status_from_uri(object_uri)&.account&.local?
|
status_from_uri(object_uri)&.account&.local?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def lock_options
|
||||||
|
{ redis: Redis.current, key: "announce:#{@object['id']}" }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue