Commit bd016009 by Jon Moss

Merge pull request #2091 from mattbrictson/lazy-fingerprint

Skip calculating fingerprint when it is not used
parents 8667baac 53a386c5
...@@ -427,7 +427,7 @@ module Paperclip ...@@ -427,7 +427,7 @@ module Paperclip
def assign_attributes def assign_attributes
@queued_for_write[:original] = @file @queued_for_write[:original] = @file
assign_file_information assign_file_information
assign_fingerprint(@file.fingerprint) assign_fingerprint { @file.fingerprint }
assign_timestamps assign_timestamps
end end
...@@ -437,9 +437,9 @@ module Paperclip ...@@ -437,9 +437,9 @@ module Paperclip
instance_write(:file_size, @file.size) instance_write(:file_size, @file.size)
end end
def assign_fingerprint(fingerprint) def assign_fingerprint
if instance_respond_to?(:fingerprint) if instance_respond_to?(:fingerprint)
instance_write(:fingerprint, fingerprint) instance_write(:fingerprint, yield)
end end
end end
...@@ -465,7 +465,7 @@ module Paperclip ...@@ -465,7 +465,7 @@ module Paperclip
def reset_file_if_original_reprocessed def reset_file_if_original_reprocessed
instance_write(:file_size, @queued_for_write[:original].size) instance_write(:file_size, @queued_for_write[:original].size)
assign_fingerprint(@queued_for_write[:original].fingerprint) assign_fingerprint { @queued_for_write[:original].fingerprint }
reset_updater reset_updater
end end
......
...@@ -1374,6 +1374,12 @@ describe Paperclip::Attachment do ...@@ -1374,6 +1374,12 @@ describe Paperclip::Attachment do
end end
it "does not calculate fingerprint" do it "does not calculate fingerprint" do
Digest::MD5.stubs(:file)
@dummy.avatar = @file
expect(Digest::MD5).to have_received(:file).never
end
it "does not assign fingerprint" do
@dummy.avatar = @file @dummy.avatar = @file
assert_nil @dummy.avatar.fingerprint assert_nil @dummy.avatar.fingerprint
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment