Fix to delete StatusCapabilityToken when deleting status batch

This commit is contained in:
noellabo 2021-05-07 11:07:04 +09:00
parent e8f7e153e8
commit 28675f7d34

View file

@ -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