Skip to content
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

Fix CollectionProxy#load_async #45440

Merged
merged 1 commit into from
Jun 23, 2022
Merged

Conversation

casperisfine
Copy link
Contributor

Fix: #45408

Since CollectionProxy inherits from Relation, load_async would schedule the query and store in it an instance variable but would never use it.

Ideally we should make the Association classes async aware so that that you can indeed schedule an association to be loaded, but that's quite a big refactoring, and would be hard to backport to 7-0-stable.

So this is a more focused fix. We delegate load_async to scope which means we return an async Relation that can later be used.

However the association isn't marked as loaded, so if you use the association later, you'll trigger a second query anyway.

I'll try to address this in a followup that won't be backported.

I'll add a CHANGELOG entry in the backport commit.

Fix: rails#45408

Since `CollectionProxy` inherits from `Relation`, `load_async`
would schedule the query and store in it an instance variable
but would never use it.

Ideally we should make the `Association` classes async aware so that
that you can indeed schedule an association to be loaded, but that's
quite a big refactoring, and would be hard to backport to 7-0-stable.

So this is a more focused fix. We delegate `load_async` to `scope`
which means we return an async `Relation` that can later be used.

However the association isn't marked as loaded, so if you use the
association later, you'll trigger a second query anyway.

I'll try to address this in a followup that won't be backported.
@byroot byroot merged commit 1dd7dcc into rails:main Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is load_async supposed to work on associations?
2 participants