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
def assign_attributes
@queued_for_write[:original] = @file
assign_file_information
assign_fingerprint(@file.fingerprint)
assign_fingerprint { @file.fingerprint }
assign_timestamps
end
......@@ -437,9 +437,9 @@ module Paperclip
instance_write(:file_size, @file.size)
end
def assign_fingerprint(fingerprint)
def assign_fingerprint
if instance_respond_to?(:fingerprint)
instance_write(:fingerprint, fingerprint)
instance_write(:fingerprint, yield)
end
end
......@@ -465,7 +465,7 @@ module Paperclip
def reset_file_if_original_reprocessed
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
end
......
......@@ -1374,6 +1374,12 @@ describe Paperclip::Attachment do
end
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
assert_nil @dummy.avatar.fingerprint
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