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

Backport perf changes #30727

Merged
merged 2 commits into from
Oct 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ def owners_by_key
end

def key_conversion_required?
@key_conversion_required ||= association_key_type != owner_key_type
unless defined?(@key_conversion_required)
@key_conversion_required = (association_key_type != owner_key_type)
end

@key_conversion_required
end

def convert_key(key)
Expand Down
31 changes: 17 additions & 14 deletions activerecord/lib/active_record/relation/query_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1177,21 +1177,24 @@ def where_clause_factory
end
alias having_clause_factory where_clause_factory

DEFAULT_VALUES = {
create_with: FROZEN_EMPTY_HASH,
readonly: false,
where: Relation::WhereClause.empty,
having: Relation::WhereClause.empty,
from: Relation::FromClause.empty
}

Relation::MULTI_VALUE_METHODS.each do |value|
DEFAULT_VALUES[value] ||= FROZEN_EMPTY_ARRAY
end

Relation::SINGLE_VALUE_METHODS.each do |value|
DEFAULT_VALUES[value] = nil if DEFAULT_VALUES[value].nil?
end

def default_value_for(name)
case name
when :create_with
FROZEN_EMPTY_HASH
when :readonly
false
when :where, :having
Relation::WhereClause.empty
when :from
Relation::FromClause.empty
when *Relation::MULTI_VALUE_METHODS
FROZEN_EMPTY_ARRAY
when *Relation::SINGLE_VALUE_METHODS
nil
else
DEFAULT_VALUES.fetch(name) do
raise ArgumentError, "unknown relation value #{name.inspect}"
end
end
Expand Down