Improve performances of deleting favourites when deleting accounts (#15412)

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
signup-info-prompt
ThibG 2020-12-23 01:35:02 +01:00 committed by GitHub
parent 62e42bd15b
commit 814b7775fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 2 deletions

View File

@ -9,13 +9,11 @@ class DeleteAccountService < BaseService
aliases
block_relationships
blocked_by_relationships
bookmarks
conversation_mutes
conversations
custom_filters
devices
domain_blocks
favourites
featured_tags
follow_requests
identity_proofs
@ -147,6 +145,8 @@ class DeleteAccountService < BaseService
purge_media_attachments!
purge_polls!
purge_generated_notifications!
purge_favourites!
purge_bookmarks!
purge_feeds!
purge_other_associations!
@ -178,6 +178,24 @@ class DeleteAccountService < BaseService
Notification.where(from_account: @account).in_batches.delete_all
end
def purge_favourites!
@account.favourites.in_batches do |favourites|
ids = favourites.pluck(:status_id)
StatusStat.where(status_id: ids).update_all('favourites_count = GREATEST(0, favourites_count - 1)')
Chewy.strategy.current.update(StatusesIndex, ids) if Chewy.enabled?
# Rails.cache.delete_multi would be better, but we don't have it yet
ids.each { |id| Rails.cache.delete("statuses/#{id}") }
favourites.delete_all
end
end
def purge_bookmarks!
@account.bookmarks.in_batches do |bookmarks|
Chewy.strategy.current.update(StatusesIndex, bookmarks.pluck(:status_id)) if Chewy.enabled?
bookmarks.delete_all
end
end
def purge_other_associations!
associations_for_destruction.each do |association_name|
purge_association(association_name)