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

Load only needed records on ActiveRecord::Relation#inspect #28592

Merged
merged 1 commit into from Mar 29, 2017

Conversation

Projects
None yet
6 participants
@htanata
Contributor

htanata commented Mar 29, 2017

Instead of loading all records and returning only a subset of those, just load the records as needed.

The original behavior could be bad when someone types User.where(...) on console and accidentally presses enter before they finish, causing a lot of records to be queried and loaded, although only 10 is shown.

To query and inspect all, we can use to_a instead, e.g. User.all.to_a.inspect.

Fixes #25537.

Load only needed records on ActiveRecord::Relation#inspect
Instead of loading all records and returning only a subset of those,
just load the records as needed.

Fixes #25537.
@rails-bot

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot Mar 29, 2017

r? @pixeltrix

(@rails-bot has picked a reviewer for you, use r? to override)

rails-bot commented Mar 29, 2017

r? @pixeltrix

(@rails-bot has picked a reviewer for you, use r? to override)

@rafaelfranca rafaelfranca merged commit eccc149 into rails:master Mar 29, 2017

2 checks passed

codeclimate no new or fixed issues
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

rafaelfranca added a commit that referenced this pull request Mar 29, 2017

Merge pull request #28592 from htanata/ar_relation_inspect_should_not…
…_load_all_records

Load only needed records on ActiveRecord::Relation#inspect

rafaelfranca added a commit that referenced this pull request Mar 29, 2017

Merge pull request #28592 from htanata/ar_relation_inspect_should_not…
…_load_all_records

Load only needed records on ActiveRecord::Relation#inspect
@rafaelfranca

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Mar 29, 2017

Member

Backported in ff03957 and 8f10e1b

Member

rafaelfranca commented Mar 29, 2017

Backported in ff03957 and 8f10e1b

@htanata

This comment has been minimized.

Show comment
Hide comment
@htanata

htanata Mar 29, 2017

Contributor

Nice that it's backported too. Thanks @rafaelfranca!

Contributor

htanata commented Mar 29, 2017

Nice that it's backported too. Thanks @rafaelfranca!

matthewd added a commit that referenced this pull request Apr 2, 2017

Revert "Merge pull request #28592 from htanata/ar_relation_inspect_sh…
…ould_not_load_all_records"

This reverts commit 8f10e1b.

There's a small chance this will create an observable behaviour change,
and that doesn't seem worthwhile in a back-branch.
@matthewd

This comment has been minimized.

Show comment
Hide comment
@matthewd

matthewd Apr 2, 2017

Member

Reverted on 5-0-stable, because making inspect no longer leave the relation loaded seems more risky than it's worth on a stable branch.

Member

matthewd commented Apr 2, 2017

Reverted on 5-0-stable, because making inspect no longer leave the relation loaded seems more risky than it's worth on a stable branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment