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

Make CollectionAssociation first/last with integer fetch with query #12137

Merged
merged 1 commit into from Sep 12, 2013

Conversation

@lann
Copy link
Contributor

@lann lann commented Sep 4, 2013

When first or last is called with an integer on an unloaded association,
the entire collection is loaded. This differs surprisingly from the
behavior of Relation#first/last, which translate the call into a limit
query. For large collections this can make a big difference in
performance.

Change CollectionAssociation#fetch_first_or_last_using_find? to make
this kind of call delegate to Relation.

@robin850
Copy link
Member

@robin850 robin850 commented Sep 7, 2013

Thanks for your contribution! Could you please add a changelog entry ?

When first or last is called with an integer on an unloaded association,
the entire collection is loaded. This differs surprisingly from the
behavior of Relation#first/last, which translate the call into a limit
query. For large collections this can make a big difference in
performance.

Change CollectionAssociation#fetch_first_or_last_using_find? to make
this kind of call delegate to Relation.
@lann
Copy link
Contributor Author

@lann lann commented Sep 10, 2013

@robin850 Changelog updated.

rafaelfranca added a commit that referenced this pull request Sep 12, 2013
Make CollectionAssociation first/last with integer fetch with query

Conflicts:
	activerecord/CHANGELOG.md
@rafaelfranca rafaelfranca merged commit 8875e28 into rails:master Sep 12, 2013
1 check passed
1 check passed
default The Travis CI build passed
Details
@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Sep 12, 2013

Make sense. Thanks

@lann lann deleted the lann:fix_association_first_last branch Sep 13, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.