Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to add RedisLock to handle Announce activity #14365

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions app/lib/activitypub/activity/announce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity
def perform
return reject_payload! if delete_arrived_first?(@json['id']) || !related_to_local_activity?

original_status = status_from_object
RedisLock.acquire(lock_options) do |lock|
if lock.acquired?
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!(
account: @account,
reblog: original_status,
uri: @json['id'],
created_at: @json['published'],
override_timestamps: @options[:override_timestamps],
visibility: visibility_from_audience
)
@status = Status.create!(
account: @account,
reblog: original_status,
uri: @json['id'],
created_at: @json['published'],
override_timestamps: @options[:override_timestamps],
visibility: visibility_from_audience
)

distribute(status)
status
distribute(@status)
else
raise Mastodon::RaceConditionError
end
end

@status
end

private
Expand Down Expand Up @@ -54,4 +61,8 @@ def requested_through_relay?
def reblog_of_local_status?
status_from_uri(object_uri)&.account&.local?
end

def lock_options
{ redis: Redis.current, key: "announce:#{@object['id']}" }
end
end