Skip to content

Commit

Permalink
Merge pull request #63 from MozillaSocial/fixDelete
Browse files Browse the repository at this point in the history
Delete attachment async when the admin status API is triggered
  • Loading branch information
bakulf authored Feb 22, 2024
2 parents 528b24e + 3f57696 commit 63a5f52
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/admin/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def destroy
if @status.with_media?
# Immediately remove public copy of media instead of waiting for
# the vacuum_orphaned_records job to take care of it later on
Admin::MediaAttachmentDeletionWorker.perform_inline(@status.media_attachments)
Admin::MediaAttachmentDeletionWorker.perform_async(@status.media_attachments.map(&:id))
end
end

Expand Down
3 changes: 2 additions & 1 deletion app/workers/admin/media_attachment_deletion_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class Admin::MediaAttachmentDeletionWorker

sidekiq_options queue: 'pull', lock: :until_executed, lock_ttl: 1.week.to_i

def perform(media_attachments)
def perform(media_attachment_ids)
media_attachments = MediaAttachment.where(id: media_attachment_ids)
AttachmentBatch.new(MediaAttachment, media_attachments).clear
end
end
4 changes: 2 additions & 2 deletions spec/workers/admin/media_attachment_deletion_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
let!(:local_media) { Fabricate(:media_attachment, status: local_status) }

it 'deletes remote media attachments' do
subject.perform([remote_media])
subject.perform([remote_media.id])
expect(remote_media.reload.file).to be_blank
end

it 'deletes local media attachments' do
subject.perform([local_media])
subject.perform([local_media.id])
expect(local_media.reload.file).to be_blank
end
end
Expand Down

0 comments on commit 63a5f52

Please sign in to comment.