Refactor how Redis locks are created (#18400)
* Refactor how Redis locks are created * Fix autorelease duration on account deletion lock
This commit is contained in:
parent
12535568f7
commit
6cf57c6765
16 changed files with 112 additions and 179 deletions
|
@ -4,6 +4,7 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
include JsonLdHelper
|
||||
include DomainControlHelper
|
||||
include Redisable
|
||||
include Lockable
|
||||
|
||||
# Should be called with confirmed valid JSON
|
||||
# and WebFinger-resolved username and domain
|
||||
|
@ -17,22 +18,18 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
@domain = domain
|
||||
@collections = {}
|
||||
|
||||
RedisLock.acquire(lock_options) do |lock|
|
||||
if lock.acquired?
|
||||
@account = Account.remote.find_by(uri: @uri) if @options[:only_key]
|
||||
@account ||= Account.find_remote(@username, @domain)
|
||||
@old_public_key = @account&.public_key
|
||||
@old_protocol = @account&.protocol
|
||||
@suspension_changed = false
|
||||
with_lock("process_account:#{@uri}") do
|
||||
@account = Account.remote.find_by(uri: @uri) if @options[:only_key]
|
||||
@account ||= Account.find_remote(@username, @domain)
|
||||
@old_public_key = @account&.public_key
|
||||
@old_protocol = @account&.protocol
|
||||
@suspension_changed = false
|
||||
|
||||
create_account if @account.nil?
|
||||
update_account
|
||||
process_tags
|
||||
create_account if @account.nil?
|
||||
update_account
|
||||
process_tags
|
||||
|
||||
process_duplicate_accounts! if @options[:verified_webfinger]
|
||||
else
|
||||
raise Mastodon::RaceConditionError
|
||||
end
|
||||
process_duplicate_accounts! if @options[:verified_webfinger]
|
||||
end
|
||||
|
||||
return if @account.nil?
|
||||
|
@ -289,10 +286,6 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
!@old_protocol.nil? && @old_protocol != @account.protocol
|
||||
end
|
||||
|
||||
def lock_options
|
||||
{ redis: redis, key: "process_account:#{@uri}", autorelease: 15.minutes.seconds }
|
||||
end
|
||||
|
||||
def process_tags
|
||||
return if @json['tag'].blank?
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue