Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete attachment async when the admin status API is triggered #63

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same change needs to be made in status_batch_action.rb

btw do we know how soon is the expected execution of a perform_async task? It should not be later than a couple minutes (if e.g. we need to take down a particularly egregious piece of media)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up for the fix!

About the timing, it's just an async call. Locally it's triggered after less than 1 second.

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
Loading