Handle duplicate account deletions
This commit is contained in:
parent
b920ddbff5
commit
6d5647ec11
2 changed files with 26 additions and 1 deletions
|
|
@ -10,7 +10,11 @@ module Diaspora
|
|||
end
|
||||
|
||||
def self.account_deletion(entity)
|
||||
AccountDeletion.create!(person: author_of(entity))
|
||||
person = author_of(entity)
|
||||
AccountDeletion.create!(person: person) unless AccountDeletion.where(person: person).exists?
|
||||
rescue => e # rubocop:disable Lint/RescueWithoutErrorClass
|
||||
raise e unless AccountDeletion.where(person: person).exists?
|
||||
logger.warn "ignoring error on receive AccountDeletion:#{entity.author}: #{e.class}: #{e.message}"
|
||||
end
|
||||
|
||||
def self.account_migration(entity)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,27 @@ describe Diaspora::Federation::Receive do
|
|||
|
||||
expect(AccountDeletion.exists?(person: sender)).to be_truthy
|
||||
end
|
||||
|
||||
it "ignores duplicate the account deletion" do
|
||||
AccountDeletion.create(person: sender)
|
||||
|
||||
expect(AccountDeletion).not_to receive(:create!)
|
||||
|
||||
Diaspora::Federation::Receive.account_deletion(account_deletion_entity)
|
||||
|
||||
expect(AccountDeletion.exists?(person: sender)).to be_truthy
|
||||
end
|
||||
|
||||
it "handles race conditions on parallel receive" do
|
||||
expect(AccountDeletion).to receive(:create!) do
|
||||
AccountDeletion.create(person: sender)
|
||||
raise "Some database error"
|
||||
end
|
||||
|
||||
Diaspora::Federation::Receive.account_deletion(account_deletion_entity)
|
||||
|
||||
expect(AccountDeletion.exists?(person: sender)).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe ".account_migration" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue