about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-12-23 01:35:02 +0100
committerGitHub <noreply@github.com>2020-12-23 01:35:02 +0100
commit814b7775fbb175bf6fb30e7f775b77c334658a8a (patch)
treec962f8825a114feb832c4b616b458ae1cba4e681 /app/services
parent62e42bd15be081596773d2b29009e437ebf27d8b (diff)
Improve performances of deleting favourites when deleting accounts (#15412)
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
Diffstat (limited to 'app/services')
-rw-r--r--app/services/delete_account_service.rb22
1 files changed, 20 insertions, 2 deletions
diff --git a/app/services/delete_account_service.rb b/app/services/delete_account_service.rb
index 58f6ef2ab..2bb533cfb 100644
--- a/app/services/delete_account_service.rb
+++ b/app/services/delete_account_service.rb
@@ -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)