Skip to content

Commit

Permalink
Fix to delete StatusCapabilityToken when deleting status batch
Browse files Browse the repository at this point in the history
  • Loading branch information
noellabo committed Aug 19, 2021
1 parent 5c842eb commit 0e3d3e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/services/batched_remove_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion spec/services/batched_remove_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0e3d3e0

Please sign in to comment.