aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/lib/active_storage/attached
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2018-03-04 17:52:49 -0500
committerGeorge Claghorn <george@basecamp.com>2018-03-04 17:56:45 -0500
commit4ed4c75c1fafd00646108771dedddeb1498796d8 (patch)
treef8ddf1868cfc1bfc9c8f994cacd0d2e6c3567901 /activestorage/lib/active_storage/attached
parent092e4d7d9ffe621061e72471b95debe12d41f342 (diff)
downloadrails-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/attached')
-rw-r--r--activestorage/lib/active_storage/attached/one.rb8
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)