diff options
| author | Sean Griffin <sean@seantheprogrammer.com> | 2017-09-07 17:30:55 -0600 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-07 17:30:55 -0600 | 
| commit | 01424eeec4038b57d7380fb81454a9a29c881416 (patch) | |
| tree | e3566ea074f62300a66d8c2726c6dcea00c516fe | |
| parent | b442cb0d915f64315e6c43aa19719df74a29fe5e (diff) | |
| parent | 338127869a4b62ddda5c75647ac1fb928361db70 (diff) | |
| download | rails-01424eeec4038b57d7380fb81454a9a29c881416.tar.gz rails-01424eeec4038b57d7380fb81454a9a29c881416.tar.bz2 rails-01424eeec4038b57d7380fb81454a9a29c881416.zip | |
Merge pull request #30524 from tgxworld/recover_plucK_performance
PERF: Recover `ActiveRecord::pluck` performance.
| -rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 31 | 
1 files changed, 17 insertions, 14 deletions
| diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index bdc5c27328..c88603fde2 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -1172,21 +1172,24 @@ module ActiveRecord        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 | 
