-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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 incorrect caching of case-insensitivity #46568
Conversation
4714d66
to
be318ae
Compare
activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
Outdated
Show resolved
Hide resolved
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
Outdated
Show resolved
Hide resolved
1425457
to
1742fd4
Compare
@case_insensitive_cache[column.sql_type] = | ||
@case_insensitive_cache.fetch(column.sql_type) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@case_insensitive_cache[column.sql_type] = | |
@case_insensitive_cache.fetch(column.sql_type) do | |
@case_insensitive_cache.fetch(column.sql_type) do | |
@case_insensitive_cache[column.sql_type] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something fishy is going on here.
With this suggested change, we're basically getting rid of a redundant c[t] = c[t]
when there's a t
key in c
already.
I'm uncertain if the same conditions as in "do not modify the array during iteration" apply here, but I'd rather keep on the safe side.
I'll revert this change if you don't object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it should be fine. I can have a look at the CI failure in a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I think it's missing a begin/end
The code looks correct to me now, please squash the two commits though. However I need to have a look at that CI failure, I don't know 100% it's unrelated. |
d491de6
to
1742fd4
Compare
`false` values would not cache with `||=`, and `begin` would run each time.
1742fd4
to
6eb54a0
Compare
…hecks Fix incorrect caching of case-insensitivity
Manually merged as b39050e. Thanks. |
Thank you, @byroot ! |
Motivation / Background
This Pull Request has been created to prevent multiple queries checking column insensitive comparison capability.
Detail
false
values would not cache with||=
, andbegin
would run each time.Instead, checking if a key for a certain column is present in the cache prevents running the query again.
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]