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

Projects
None yet
3 participants
@lann
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@robin850

robin850 Sep 7, 2013

Member

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

Member

robin850 commented Sep 7, 2013

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

Make CollectionAssociation first/last with integer fetch with query
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

This comment has been minimized.

Show comment
Hide comment
@lann

lann Sep 10, 2013

Contributor

@robin850 Changelog updated.

Contributor

lann commented Sep 10, 2013

@robin850 Changelog updated.

rafaelfranca added a commit that referenced this pull request Sep 12, 2013

Merge pull request #12137 from lann/fix_association_first_last
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

default The Travis CI build passed
Details
@rafaelfranca

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Sep 12, 2013

Member

Make sense. Thanks

Member

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