When creating a variant, I am seeing slow times just to check if the file exists. The strange thing is that I do not see the slow times when the file gets uploaded. How can we speed this up?
It happens when you call something like this.
@object.artwork.variant(resize: "100X100")
Notice the slow time (over 1 second!) just to check if the file exists.
S3 Storage (1149.3ms) Checked if file exists at key: variants/K6XGSR9uuyEG17Vd6HXSLyew/4c1922cb9e0ee90688549c6a10906cc59c45f90ab173febdd7ae9dfc72c0378b
You can recreate in the console with
ActiveStorage::Blob.service.exist?("variants/K6XGSR9uuyEG17Vd6HXSLyew/4c1922cb9e0ee90688549c6a10906cc59c45f90ab173febdd7ae9dfc72c0378b")
The above is an actual example from production, but normally we see average times in the 300ms range.
I think this is just the way it works. I'd suggest storing your variants as separate attachments instead.
There's an issue on the Rails GitHub about it:
https://github.com/rails/rails/issues/32548
February 2020 update: storing variant records in the database is coming in Rails 6.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With