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 preloading on AR::Relation where records are duplicated by a join #36429

Merged
merged 1 commit into from Jun 6, 2019

Conversation

Projects
None yet
2 participants
@bogdan
Copy link
Contributor

commented Jun 6, 2019

Problem

Fixes #36396

Solution

Using an unknown Hash#compare_by_identity to allow equal hash keys.
When hash has this feature enabled, cache keys become unique using key1.object_id == key2.object_id not key1 == key2.

❤️ ❤️ ❤️ RUBY ❤️ ❤️ ❤️

https://apidock.com/ruby/Hash/compare_by_identity

cc @kamipo @pstare

@rails-bot rails-bot bot added the activerecord label Jun 6, 2019

@bogdan bogdan force-pushed the bogdan:fix-preloading-duplicate-records branch from 6ce2286 to 2250c8a Jun 6, 2019

@bogdan bogdan force-pushed the bogdan:fix-preloading-duplicate-records branch from 2250c8a to 30c1999 Jun 6, 2019

@kamipo

This comment has been minimized.

Copy link
Member

commented Jun 6, 2019

Is there no need to change these?

@records_by_owner ||= owners.each_with_object({}) do |owner, result|

@records_by_owner = owners.each_with_object({}) do |owner, result|

@kamipo

This comment has been minimized.

Copy link
Member

commented Jun 6, 2019

I've confirmed, unlike (result[owner] ||= []) << record, result[owner] = ... has no side-effect even if owners are duplicated.

result[owner] = Array(owner.association(reflection.name).target)

@kamipo kamipo merged commit e3c1f42 into rails:master Jun 6, 2019

2 checks passed

buildkite/rails Build #61566 passed (8 minutes, 2 seconds)
Details
codeclimate All good!
Details

rafaelfranca added a commit that referenced this pull request Jun 6, 2019

Merge pull request #36429 from bogdan/fix-preloading-duplicate-records
Fix preloading on AR::Relation where records are duplicated by a join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.