Destroy user and person associations in batches
This commit is contained in:
parent
4e6d92ce63
commit
f4902421ea
2 changed files with 25 additions and 14 deletions
|
|
@ -5,7 +5,6 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class AccountDeleter
|
class AccountDeleter
|
||||||
|
|
||||||
# Things that are not removed from the database:
|
# Things that are not removed from the database:
|
||||||
# - Comments
|
# - Comments
|
||||||
# - Likes
|
# - Likes
|
||||||
|
|
@ -61,13 +60,17 @@ class AccountDeleter
|
||||||
|
|
||||||
def delete_standard_user_associations
|
def delete_standard_user_associations
|
||||||
normal_ar_user_associates_to_delete.each do |asso|
|
normal_ar_user_associates_to_delete.each do |asso|
|
||||||
self.user.send(asso).each{|model| model.destroy }
|
user.send(asso).ids.each_slice(20) do |ids|
|
||||||
|
User.reflect_on_association(asso).class_name.constantize.where(id: ids).destroy_all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_standard_person_associations
|
def delete_standard_person_associations
|
||||||
normal_ar_person_associates_to_delete.each do |asso|
|
normal_ar_person_associates_to_delete.each do |asso|
|
||||||
self.person.send(asso).destroy_all
|
person.send(asso).ids.each_slice(20) do |ids|
|
||||||
|
Person.reflect_on_association(asso).class_name.constantize.where(id: ids).destroy_all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -78,7 +81,7 @@ class AccountDeleter
|
||||||
# Currently this would get deleted due to the db foreign key constrainsts,
|
# Currently this would get deleted due to the db foreign key constrainsts,
|
||||||
# but we'll keep this method here for completeness
|
# but we'll keep this method here for completeness
|
||||||
def remove_share_visibilities_on_contacts_posts
|
def remove_share_visibilities_on_contacts_posts
|
||||||
ShareVisibility.for_a_user(user).destroy_all
|
ShareVisibility.for_a_user(user).find_each(batch_size: 20, &:destroy)
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_conversation_visibilities
|
def remove_conversation_visibilities
|
||||||
|
|
@ -86,16 +89,16 @@ class AccountDeleter
|
||||||
end
|
end
|
||||||
|
|
||||||
def tombstone_person_and_profile
|
def tombstone_person_and_profile
|
||||||
self.person.lock_access!
|
person.lock_access!
|
||||||
self.person.clear_profile!
|
person.clear_profile!
|
||||||
end
|
end
|
||||||
|
|
||||||
def tombstone_user
|
def tombstone_user
|
||||||
self.user.clear_account!
|
user.clear_account!
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_contacts_of_me
|
def delete_contacts_of_me
|
||||||
Contact.all_contacts_of_person(self.person).destroy_all
|
Contact.all_contacts_of_person(person).find_each(batch_size: 20, &:destroy)
|
||||||
end
|
end
|
||||||
|
|
||||||
def normal_ar_person_associates_to_delete
|
def normal_ar_person_associates_to_delete
|
||||||
|
|
|
||||||
|
|
@ -96,8 +96,12 @@ describe AccountDeleter do
|
||||||
it 'removes all standard user associaltions' do
|
it 'removes all standard user associaltions' do
|
||||||
@account_deletion.normal_ar_user_associates_to_delete.each do |asso|
|
@account_deletion.normal_ar_user_associates_to_delete.each do |asso|
|
||||||
association_double = double
|
association_double = double
|
||||||
expect(association_double).to receive(:destroy)
|
expect(association_double).to receive(:ids).and_return([42])
|
||||||
expect(bob).to receive(asso).and_return([association_double])
|
expect(bob).to receive(asso).and_return(association_double)
|
||||||
|
batch_double = double
|
||||||
|
expect(User.reflect_on_association(asso).class_name.constantize).to receive(:where)
|
||||||
|
.with(id: [42]).and_return(batch_double)
|
||||||
|
expect(batch_double).to receive(:destroy_all)
|
||||||
end
|
end
|
||||||
|
|
||||||
@account_deletion.delete_standard_user_associations
|
@account_deletion.delete_standard_user_associations
|
||||||
|
|
@ -111,8 +115,12 @@ describe AccountDeleter do
|
||||||
it 'removes all standard person associaltions' do
|
it 'removes all standard person associaltions' do
|
||||||
@account_deletion.normal_ar_person_associates_to_delete.each do |asso|
|
@account_deletion.normal_ar_person_associates_to_delete.each do |asso|
|
||||||
association_double = double
|
association_double = double
|
||||||
expect(association_double).to receive(:destroy_all)
|
expect(association_double).to receive(:ids).and_return([42])
|
||||||
expect(bob.person).to receive(asso).and_return(association_double)
|
expect(bob.person).to receive(asso).and_return(association_double)
|
||||||
|
batch_double = double
|
||||||
|
expect(Person.reflect_on_association(asso).class_name.constantize).to receive(:where)
|
||||||
|
.with(id: [42]).and_return(batch_double)
|
||||||
|
expect(batch_double).to receive(:destroy_all)
|
||||||
end
|
end
|
||||||
|
|
||||||
@account_deletion.delete_standard_person_associations
|
@account_deletion.delete_standard_person_associations
|
||||||
|
|
@ -133,7 +141,7 @@ describe AccountDeleter do
|
||||||
it 'deletes all the local contact objects where deleted account is the person' do
|
it 'deletes all the local contact objects where deleted account is the person' do
|
||||||
contacts = double
|
contacts = double
|
||||||
expect(Contact).to receive(:all_contacts_of_person).with(bob.person).and_return(contacts)
|
expect(Contact).to receive(:all_contacts_of_person).with(bob.person).and_return(contacts)
|
||||||
expect(contacts).to receive(:destroy_all)
|
expect(contacts).to receive(:find_each).with(batch_size: 20)
|
||||||
@account_deletion.delete_contacts_of_me
|
@account_deletion.delete_contacts_of_me
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -163,7 +171,7 @@ describe AccountDeleter do
|
||||||
it "removes the share visibilities for a user" do
|
it "removes the share visibilities for a user" do
|
||||||
s_vis = double
|
s_vis = double
|
||||||
expect(ShareVisibility).to receive(:for_a_user).with(bob).and_return(s_vis)
|
expect(ShareVisibility).to receive(:for_a_user).with(bob).and_return(s_vis)
|
||||||
expect(s_vis).to receive(:destroy_all)
|
expect(s_vis).to receive(:find_each).with(batch_size: 20)
|
||||||
|
|
||||||
@account_deletion.remove_share_visibilities_on_contacts_posts
|
@account_deletion.remove_share_visibilities_on_contacts_posts
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue