-
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 eager loading: support more methods #42981
Conversation
8f87cf1
to
0fce237
Compare
Wow, thank you so much! I was struggling to find a solution... I couldn't find where in the call chain the blob was loaded again. Now from your work I guess that the I have quickly tested this in our application and everything seems to work, perfect. |
Hmmm, this has broken some tests. I think this solution might have other issues. Will investigate but probably not before tomorrow. |
e1fcedc
to
b6c8aa1
Compare
There's one thing that I don't understand in the new code: (let |
As in my previous comment, I confirm that we need to call The |
@georgeclaghorn I see that you originally wrote the code for |
I think I'll have some more time tomorrow to work on this |
99b06af
to
4739afe
Compare
Simplified my approach, the solution is just to add the missing |
8dab38c
to
b7eb4bd
Compare
Thanks for this improvement! So in order to get the
That's really deep nesting... I expected to be able to compute the Variant key directly from the Variant, I didn't expected that the Variant doesn't represent the file, but it needs to be attached again to the actual file (Blob). I don't understand this choice, but I guess there are good reasons for that. Also this is not a decision made now by this pull request, but it was made when the Variant was stored in the database. In any case I have tested this PR in production (together with #40842) and it seems to work great! Despite the deep nesting, I've seen a 10x improvement on pages that have hundreds of images. Thanks again! |
Can someone merge this? It's really useful for performance |
@pixeltrix could I bother you for a review here? It's just fixing a bug in #40842 |
@ghiculescu while you're here, can you please apply the same fixes to the They suffer from the same N+1 issue when doing bulk queries, and would benefit from the same deep |
b7eb4bd
to
fdc803f
Compare
fdc803f
to
5a1e1df
Compare
As noted at rails#40842 (comment), the current implementation works great with the `processed` method, but doesn't work with other methods such as `key`. This PR fixes that. Why is this fix necessary? Currently when you call `VariantWithRecord#key`, `key` gets called on `VariantWithRecord` -> `Attached::One` -> `Attachment` -> `Blob`. This results in n+1 calls to load the `Attachment`. But for this purpose we shouldn't need to load it, as the `VariantWithRecord` already knows about it relevant `Blob`. So this PR changes the method to call directly to that blob.
5a1e1df
to
675264a
Compare
@rafaelfranca this fixes a bug that was found in 7.0 alpha, could it please be included in the next RC? |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Keep it open. Please someone should merge this... |
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.
Good one @ghiculescu 👍. We'll get this one merged (cc @jeremy).
* main: (746 commits) Address QueryCacheTest#test_query_cache_does_not_allow_sql_key_mutation failure Fixes ActiveStorage proxy downloads of files over 5mb in S3-like storage services Fixes development Action Mailbox new mail form Squash commits Include the unexpected class in InvalidParameterKey message Support unbounded time ranges for PostgreSQL Fix CHANGELOG alignment [ci-skip] Add ability to ignore tables by regexp for SQL schema dumps Improve `rails s` error message when no server could be found. Fix MySQL warning when creating Active Record's test databases Add `--js` and --skip-javascript` options to `rails new` Fix parsing operator classes for index columns in PostgreSQL Fix rails test command to handle leading dot slash Document that url_for can take classes Don't change the encoding of frozen parameters Update working_with_javascript_in_rails.md Avoid query from calculations on contradictory relation Fix MemoryStore#write(name, val, unless_exist: true) with expired entry Provide pattern matching for ActiveModel Stop autoclosing of PRs ...
Thanks! |
Great, thanks 🎉 |
As noted at #40842 (comment), the current implementation works great with the
processed
method, but doesn't work with other methods such askey
. This PR fixes that, by adding the missingincludes
statements.cc @collimarco