Fix mentions not being deleted efficiently (#15416)

As a regression from the recent optimizations, mentions were left untouched
until `account.destroy`, which would then delete them individually,
and executing queries to find and delete associated notifications, resulting
in a massive slowdown.

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
main
ThibG 2020-12-23 16:43:11 +01:00 committed by GitHub
parent 473abc35a1
commit de57efd055
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -142,6 +142,7 @@ class DeleteAccountService < BaseService
purge_user! purge_user!
purge_profile! purge_profile!
purge_statuses! purge_statuses!
purge_mentions!
purge_media_attachments! purge_media_attachments!
purge_polls! purge_polls!
purge_generated_notifications! purge_generated_notifications!
@ -159,6 +160,10 @@ class DeleteAccountService < BaseService
end end
end end
def purge_mentions!
@account.mentions.reorder(nil).where.not(status_id: reported_status_ids).in_batches.delete_all
end
def purge_media_attachments! def purge_media_attachments!
@account.media_attachments.reorder(nil).find_each do |media_attachment| @account.media_attachments.reorder(nil).find_each do |media_attachment|
next if keep_account_record? && reported_status_ids.include?(media_attachment.status_id) next if keep_account_record? && reported_status_ids.include?(media_attachment.status_id)