Skip to content

Commit

Permalink
Merge pull request #30524 from tgxworld/recover_plucK_performance
Browse files Browse the repository at this point in the history
PERF: Recover `ActiveRecord::pluck` performance.
  • Loading branch information
sgrif committed Sep 7, 2017
2 parents b442cb0 + 3381278 commit 01424ee
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions activerecord/lib/active_record/relation/query_methods.rb
Expand Up @@ -1172,21 +1172,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?

This comment has been minimized.

Copy link
@ryanfox1985

ryanfox1985 Sep 8, 2017

This line has no sense.

DEFAULT_VALUES[value] is nil already if key(value) is not present.

This comment has been minimized.

Copy link
@ryanfox1985

This comment has been minimized.

Copy link
@tgxworld
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

0 comments on commit 01424ee

Please sign in to comment.