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
Eagerly load preview images (N+1) #50758
Conversation
2de77b2
to
ad2c98b
Compare
Co-Authored-By: Justin Searls <searls@gmail.com>
For non-image attachments (like videos), generated representations are created as a preview_image_attachment instead of as normal variants, and as a result aren't included in the `with_attached_` scopes. This adds those preview image attachments to the `includes` of these scopes to avoid an N+1 when iterating over a collection of attachments and fetching the key of their representation (variants). Co-Authored-By: Justin Searls <searls@gmail.com>
a8bb8dd
to
4a18e06
Compare
There is a similar scope that should probably be changed as well (maybe in another PR):
|
Co-authored-by: Petrik de Heus <petrik@deheus.net>
Good call. I added a test / fix for this in this PR since I think we should backport this. |
c418969
to
7e9b588
Compare
Thanks so much for helping with this!! 🙏 |
Eagerly load preview images (N+1)
Merge pull request #50758 from rails/fix-video-preview-nplus1
This should be part of a bigger release IMHO as this breaks apps using non-UUID PKs in their blob tables whilst the FK actually uses UUIDs w/o a deprecation warning. Another option could be a documented way to disable the preloading. |
@boof Could you create an issue? |
For non-image attachments (like videos), generated representations are
created as a preview_image_attachment instead of as normal variants, and
as a result aren't included in the
with_attached_
scopes. This addsthose preview image attachments to the
includes
of these scopes toavoid an N+1 when iterating over a collection of attachments and
fetching the key of their representation (variants).
Fixes #50560