mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #21522 from tgxworld/scope_perf
PERF: Scope performance.
This commit is contained in:
commit
ecb4e4b21b
4 changed files with 13 additions and 5 deletions
|
@ -24,12 +24,12 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def build_from_hash(attributes)
|
||||
attributes = convert_dot_notation_to_hash(attributes.stringify_keys)
|
||||
attributes = convert_dot_notation_to_hash(attributes)
|
||||
expand_from_hash(attributes)
|
||||
end
|
||||
|
||||
def create_binds(attributes)
|
||||
attributes = convert_dot_notation_to_hash(attributes.stringify_keys)
|
||||
attributes = convert_dot_notation_to_hash(attributes)
|
||||
create_binds_for_hash(attributes)
|
||||
end
|
||||
|
||||
|
|
|
@ -10,10 +10,10 @@ module ActiveRecord
|
|||
|
||||
table = value.associated_table
|
||||
if value.base_class
|
||||
queries[table.association_foreign_type] = value.base_class.name
|
||||
queries[table.association_foreign_type.to_s] = value.base_class.name
|
||||
end
|
||||
|
||||
queries[table.association_foreign_key] = value.ids
|
||||
queries[table.association_foreign_key.to_s] = value.ids
|
||||
predicate_builder.build_from_hash(queries)
|
||||
end
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ module ActiveRecord
|
|||
when Hash
|
||||
attributes = predicate_builder.resolve_column_aliases(opts)
|
||||
attributes = klass.send(:expand_hash_conditions_for_aggregates, attributes)
|
||||
attributes.stringify_keys!
|
||||
|
||||
attributes, binds = predicate_builder.create_binds(attributes)
|
||||
|
||||
|
|
|
@ -6,8 +6,10 @@ module ActiveRecord
|
|||
included do
|
||||
# Stores the default scope for the class.
|
||||
class_attribute :default_scopes, instance_writer: false, instance_predicate: false
|
||||
class_attribute :default_scope_override, instance_predicate: false
|
||||
|
||||
self.default_scopes = []
|
||||
self.default_scope_override = nil
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
@ -101,7 +103,12 @@ module ActiveRecord
|
|||
|
||||
def build_default_scope(base_rel = nil) # :nodoc:
|
||||
return if abstract_class?
|
||||
if !Base.is_a?(method(:default_scope).owner)
|
||||
|
||||
if self.default_scope_override.nil?
|
||||
self.default_scope_override = !Base.is_a?(method(:default_scope).owner)
|
||||
end
|
||||
|
||||
if self.default_scope_override
|
||||
# The user has defined their own default scope method, so call that
|
||||
evaluate_default_scope { default_scope }
|
||||
elsif default_scopes.any?
|
||||
|
|
Loading…
Reference in a new issue