Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When
refresh_metadata
plugin is used,UploadedFile#download
using Storage#download causes bad performance whenUploadedFile#download
is called multiple times during metadata extraction, because in that case the same file will be downloaded from the storage multiple times.Moreover, the download that
UploadedFile#refresh_metadata!
started at the beginning of metadata extraction won't be reused. It will be reused for determine_mime_type and store_dimensions plugins, but for any custom metadata that usesUploadedFile#download
(either directly or implicitly viaShrine.with_file
) a whole new download will be started.Storage#download
existed for two reasons:If
Storage#open
usesDown::ChunkedIO
, callingUploadedFile#download
the first time on anUploadedFile
object would copy the remote content to two Tempfiles: the Tempfile that's returned andDown::ChunkedIO
's internal Tempfile.Storage#download
allows storage implementers to avoid the additional copy.Some SDKs such as
aws-sdk-s3
implement automatic retries only if the download destination is a Tempfile (like inS3#download
), but not if it's a block (like inS3#open
).The 1st issue can be addressed by explicitly passing
rewindable: false
for storages that useDown::ChunkedIO
and support:rewindable
. Though it's not really a big deal anyway.The 2nd issue should be fixed in the SDK.
google-api-client
already supports resumable downloads for any download destination, and fix foraws-sdk-s3
is in the works (aws/aws-sdk-ruby#1617)I no longer believe
Storage#download
provides enough benefits to keep around. The performance issues withrefresh_metadata
plugin and custom metadata are a great reason to throw it away. An added benefit is that storages now have one less method to implement.Partially addresses #329