carrierwaveuploader / carrierwave

Classier solution for file uploads for Rails, Sinatra and other Ruby web frameworks
https://github.com/carrierwaveuploader/carrierwave
8.78k stars 1.65k forks source link

fix: dont retrieve from store until accessing file #2698

Open Amnesthesia opened 10 months ago

Amnesthesia commented 10 months ago

Carrierwave seems to try retrieve_from_store! as soon as you access #uploaders, and if a file doesn't exist on S3 (for whatever reason), it will keep retrying over and over and over, making it virtually unusable because of the amounts of retried requests

It should be possible to access the uploader, and retrieve storage path and identifier without performing network requests to retrieve the file from storage, if retrieving the file isn't needed.

This PR removes retrieve_from_store! from the @uploaders ||= setup block and instead replaces the attr_reader :file with a new method #file that will retrieve_from_store! when accessed, but only a maximum X times as defined in the configuration for download_retries before it just returns @file even if it's nil.