aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/app/models/active_storage/attachment.rb
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2017-08-29 00:02:59 -0400
committerGeorge Claghorn <george@basecamp.com>2017-08-29 00:02:59 -0400
commitd3e7dc6f16d68492a159d874f72a3a229a62f844 (patch)
tree3a13a54eda3b014dd16140815e2081cfec5b0732 /activestorage/app/models/active_storage/attachment.rb
parent99f75820bb5ab28a56844837911727808c566174 (diff)
downloadrails-d3e7dc6f16d68492a159d874f72a3a229a62f844.tar.gz
rails-d3e7dc6f16d68492a159d874f72a3a229a62f844.tar.bz2
rails-d3e7dc6f16d68492a159d874f72a3a229a62f844.zip
Synchronously destroy attachments
Diffstat (limited to 'activestorage/app/models/active_storage/attachment.rb')
-rw-r--r--activestorage/app/models/active_storage/attachment.rb10
1 files changed, 4 insertions, 6 deletions
diff --git a/activestorage/app/models/active_storage/attachment.rb b/activestorage/app/models/active_storage/attachment.rb
index ad43845e4e..2a1c20b7db 100644
--- a/activestorage/app/models/active_storage/attachment.rb
+++ b/activestorage/app/models/active_storage/attachment.rb
@@ -14,17 +14,15 @@ class ActiveStorage::Attachment < ActiveRecord::Base
delegate_missing_to :blob
- # Purging an attachment will purge the blob (delete the file on the service, then destroy the record)
- # and then destroy the attachment itself.
+ # Synchronously purges the blob (deletes it from the configured service) and destroys the attachment.
def purge
blob.purge
destroy
end
- # Purging an attachment means purging the blob, which means talking to the service, which means
- # talking over the Internet. Whenever you're doing that, it's a good idea to put that work in a job,
- # so it doesn't hold up other operations. That's what +purge_later+ provides.
+ # Destroys the attachment and asynchronously purges the blob (deletes it from the configured service).
def purge_later
- ActiveStorage::PurgeJob.perform_later(self)
+ blob.purge_later
+ destroy
end
end