From 5f2ee4c0bb790480a7032d1779052be2e1e46808 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Sun, 29 Apr 2018 07:01:44 -0400 Subject: Stream blobs from disk in 5 MB chunks Match other services, which all use a 5 MB chunk size. --- activestorage/lib/active_storage/service/disk_service.rb | 2 +- activestorage/test/models/blob_test.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/activestorage/lib/active_storage/service/disk_service.rb b/activestorage/lib/active_storage/service/disk_service.rb index 5b652fe74e..b1b6f1ddcf 100644 --- a/activestorage/lib/active_storage/service/disk_service.rb +++ b/activestorage/lib/active_storage/service/disk_service.rb @@ -26,7 +26,7 @@ module ActiveStorage if block_given? instrument :streaming_download, key: key do File.open(path_for(key), "rb") do |file| - while data = file.read(64.kilobytes) + while data = file.read(5.megabytes) yield data end end diff --git a/activestorage/test/models/blob_test.rb b/activestorage/test/models/blob_test.rb index fead17d33a..daa01015f7 100644 --- a/activestorage/test/models/blob_test.rb +++ b/activestorage/test/models/blob_test.rb @@ -62,7 +62,7 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase end test "download yields chunks" do - blob = create_blob data: "a" * 75.kilobytes + blob = create_blob data: "a" * 5.0625.megabytes chunks = [] blob.download do |chunk| @@ -70,8 +70,8 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase end assert_equal 2, chunks.size - assert_equal "a" * 64.kilobytes, chunks.first - assert_equal "a" * 11.kilobytes, chunks.second + assert_equal "a" * 5.megabytes, chunks.first + assert_equal "a" * 64.kilobytes, chunks.second end test "urls expiring in 5 minutes" do -- cgit v1.2.3