From 28675f7d345046d773815ef087b57ede77483d84 Mon Sep 17 00:00:00 2001 From: noellabo Date: Fri, 7 May 2021 11:07:04 +0900 Subject: [PATCH] Fix to delete StatusCapabilityToken when deleting status batch --- app/services/batched_remove_status_service.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/services/batched_remove_status_service.rb b/app/services/batched_remove_status_service.rb index 886dc56e8..a1acace2f 100644 --- a/app/services/batched_remove_status_service.rb +++ b/app/services/batched_remove_status_service.rb @@ -23,6 +23,10 @@ class BatchedRemoveStatusService < BaseService status.send(:unlink_from_conversations) end + status_ids_with_capability_tokens = statuses.local.joins(:capability_tokens).where.not(capability_tokens: { id: nil }).pluck(:id) + status_ids_with_capability_tokens += Status.where(reblog_of_id: statuses).local.joins(:capability_tokens).where.not(capability_tokens: { id: nil }).pluck(:id) + status_ids_with_capability_tokens.each_slice(50) { |slice| StatusCapabilityToken.where(status_id: slice).delete_all } + # We do not batch all deletes into one to avoid having a long-running # transaction lock the database, but we use the delete method instead # of destroy to avoid all callbacks. We rely on foreign keys to