Skip to content

Commit

Permalink
Merge pull request rails#50418 from the-spectator/buffered_checksum
Browse files Browse the repository at this point in the history
Use buffered read while generating Blob checksum to improve memory
  • Loading branch information
jonathanhefner authored Dec 26, 2023
2 parents 16ff9af + 92138c4 commit 5b62994
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions activestorage/app/models/active_storage/blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,9 @@ def compute_checksum_in_chunks(io)
raise ArgumentError, "io must be rewindable" unless io.respond_to?(:rewind)

OpenSSL::Digest::MD5.new.tap do |checksum|
while chunk = io.read(5.megabytes)
checksum << chunk
read_buffer = "".b
while io.read(5.megabytes, read_buffer)
checksum << read_buffer
end

io.rewind
Expand Down

0 comments on commit 5b62994

Please sign in to comment.