-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Active Storage: docs on lazy vs immediate loading #42495
Conversation
@wbharding @RSO I used some of your examples from #40842 for this. Can you please have a look and see if they make sense? @pixeltrix FYI |
@@ -687,6 +687,38 @@ previewable files. You can also call these methods directly. | |||
[`representable?`]: https://api.rubyonrails.org/classes/ActiveStorage/Blob/Representable.html#method-i-representable-3F | |||
[`representation`]: https://api.rubyonrails.org/classes/ActiveStorage/Blob/Representable.html#method-i-representation | |||
|
|||
### Lazy vs Immediate Loading |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think loading is a bit ambiguous here. Is it about lazily processing the images or about redirecting the back to the app first?
Maybe:
### Lazy vs Immediate Loading | |
### Lazy vs Immediate Processing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but in this case it's mostly about deferring the processing to another request right? At least the first time, when blobs haven't been processed...
|
||
```ruby | ||
user.avatars.with_all_variant_records.each do |file| | ||
image_tag file.representation(resize_to_limit: [100, 100]).processed.url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will process all N files on the first access right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we maybe at a warning that it can make pages slow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also bypasses HTTP caching, as it will create a new temporary url each time it's called.
So you need to either cache the url or users will download the file every time they access the page.
Co-authored-by: Petrik de Heus <petrik@deheus.net>
Late to the party, but looks good to me. A small nitpick would be that I don't think users will have many avatars typically, but that shouldn't be an issue in understanding what this is about. Side note: Is |
@RSO It's a wrapper so you don't have to think about if you need
|
@RSO maybe we should use |
Originally discovered by @RSO in #42495 (comment)
Fixed in 9c091b4 |
Follow up to #42477 (comment)