提交 ecb4e4b2 编写于 作者: R Rafael Mendonça França

Merge pull request #21522 from tgxworld/scope_perf

PERF: Scope performance.
......@@ -24,12 +24,12 @@ def initialize(table)
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 @@ def call(attribute, value)
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 @@ def build(opts, other)
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 Default
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 @@ def default_scope(scope = nil)
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?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册