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

Check that entire collection has been loaded before short circuiting #37747

Conversation

bradleyprice
Copy link
Contributor

Summary

Currently, when checking that the collection has been loaded, only the first
record is checked. In specific scenarios, if a record is fetched via an after_initialize
hook, there is a chance that the first record has been loaded, but other records in the
collection have not.

In order to successfully short circuit the fetching of data, we need to verify that
all of the records in the collection have been loaded.

  • Create test for edge case
  • Move reset_callbacks method to cases/helper, since it has been defined in multiple
    locations.

Closes #37730

Other Information

@bradleyprice bradleyprice force-pushed the check-association-loaded-across-collection-on-preload branch 3 times, most recently from e708c64 to 67ee403 Compare November 19, 2019 00:38
@bradleyprice
Copy link
Contributor Author

@kamipo I've made the requested changes. How does this get ported to rails 5.2? Should I create a separate PR for that?

@kamipo
Copy link
Member

kamipo commented Nov 19, 2019

Can you squash your commits into one?

I'll backport a bugfix to 6-0-stable (5-2-stable too) after this is getting merged, since 5-2-stable is before a final release.

Currently, when checking that the collection has been loaded, only the first
record is checked. In specific scenarios, if a record is fetched via an `after_initialize`
hook, there is a chance that the first record has been loaded, but other records in the
collection have not.

In order to successfully short circuit the fetching of data, we need to verify that
all of the records in the collection have been loaded.

* Create test for edge case
* Move `reset_callbacks` method to `cases/helper`, since it has been defined in multiple
  locations.

Closes rails#37730
@bradleyprice bradleyprice force-pushed the check-association-loaded-across-collection-on-preload branch from d8ea5d2 to 0a5b41c Compare November 19, 2019 21:33
@bradleyprice
Copy link
Contributor Author

Squashed. Thanks for the help!

kamipo added a commit that referenced this pull request Nov 19, 2019
…across-collection-on-preload

Check that entire collection has been loaded before short circuiting
@kamipo kamipo merged commit 0a5b41c into rails:master Nov 19, 2019
kamipo added a commit that referenced this pull request Nov 19, 2019
…across-collection-on-preload

Check that entire collection has been loaded before short circuiting
kamipo added a commit that referenced this pull request Nov 19, 2019
…across-collection-on-preload

Check that entire collection has been loaded before short circuiting
JesseChavez pushed a commit to JesseChavez/rails that referenced this pull request Dec 19, 2019
…aded-across-collection-on-preload

Check that entire collection has been loaded before short circuiting
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.

After_initialize on STI that references association breaks preloading
2 participants