Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

reduce object allocation during AR instantiation

  • Loading branch information...
commit 02f45d6e0ca0a3e6f5fc30b2c99bedee27484197 1 parent c290900
@tenderlove tenderlove authored
View
2  activerecord/lib/active_record/base.rb
@@ -2082,6 +2082,8 @@ def convert_number_column_value(value)
end
def populate_with_current_scope_attributes
+ return unless self.class.scope_attributes?
+
self.class.scope_attributes.each do |att,value|
send("#{att}=", value) if respond_to?("#{att}=")
end
View
9 activerecord/lib/active_record/named_scope.rb
@@ -47,15 +47,18 @@ def scope_attributes # :nodoc:
if current_scope
current_scope.scope_for_create
else
- # Return an empty hash in the simple case
- return {} unless default_scopes.any?
-
scope = relation.clone
scope.default_scoped = true
scope.scope_for_create
end
end
+ ##
+ # Are there default attributes associated with this scope?
+ def scope_attributes? # :nodoc:
+ current_scope || default_scopes.any?
+ end
+
# Adds a class method for retrieving and querying objects. A \scope represents a narrowing of a database query,
# such as <tt>where(:color => :red).select('shirts.*').includes(:washing_instructions)</tt>.
#
Please sign in to comment.
Something went wrong with that request. Please try again.