diff options
author | George Claghorn <george@basecamp.com> | 2018-03-04 17:52:49 -0500 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-03-04 17:56:45 -0500 |
commit | 4ed4c75c1fafd00646108771dedddeb1498796d8 (patch) | |
tree | f8ddf1868cfc1bfc9c8f994cacd0d2e6c3567901 /activestorage/lib/active_storage | |
parent | 092e4d7d9ffe621061e72471b95debe12d41f342 (diff) | |
download | rails-4ed4c75c1fafd00646108771dedddeb1498796d8.tar.gz rails-4ed4c75c1fafd00646108771dedddeb1498796d8.tar.bz2 rails-4ed4c75c1fafd00646108771dedddeb1498796d8.zip |
Avoid purging attached blob when replacing it with itself
Diffstat (limited to 'activestorage/lib/active_storage')
-rw-r--r-- | activestorage/lib/active_storage/attached/one.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activestorage/lib/active_storage/attached/one.rb b/activestorage/lib/active_storage/attached/one.rb index 0244232b2c..e3600dc241 100644 --- a/activestorage/lib/active_storage/attached/one.rb +++ b/activestorage/lib/active_storage/attached/one.rb @@ -64,12 +64,16 @@ module ActiveStorage private def replace(attachable) - blob.tap do + unless attachable == blob + previous_blob = blob + transaction do detach write_attachment build_attachment_from(attachable) end - end.purge_later + + previous_blob.purge_later + end end def build_attachment_from(attachable) |