From 0e3d3e02b82a4f4a15a68fcb90c4698a6d14bf67 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 ++++ spec/services/batched_remove_status_service_spec.rb | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/services/batched_remove_status_service.rb b/app/services/batched_remove_status_service.rb index 3ca241d2417c14..e36d1908b007e8 100644 --- a/app/services/batched_remove_status_service.rb +++ b/app/services/batched_remove_status_service.rb @@ -23,6 +23,10 @@ def call(statuses, **options) 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 diff --git a/spec/services/batched_remove_status_service_spec.rb b/spec/services/batched_remove_status_service_spec.rb index 4203952c60f313..65acfd3b60d4bc 100644 --- a/spec/services/batched_remove_status_service_spec.rb +++ b/spec/services/batched_remove_status_service_spec.rb @@ -23,7 +23,9 @@ status1 status2 - subject.call([status1, status2]) + statuses = Status.where(id: [status1.id, status2.id]) + + subject.call(statuses) end it 'removes statuses' do