From 4ed4c75c1fafd00646108771dedddeb1498796d8 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Sun, 4 Mar 2018 17:52:49 -0500 Subject: Avoid purging attached blob when replacing it with itself --- activestorage/lib/active_storage/attached/one.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'activestorage/lib') 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) -- cgit v1.2.3