Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

apply [8865] to 2.0 stable

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/2-0-stable@8866 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 9d03813e91802e6674f65a60ca087d7c725ed467 1 parent 5b714e7
@technoweenie technoweenie authored
View
2  activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Improve associations performance by avoiding named block arguments. #11109 [adymo]
+
* Ensure that modifying has_and_belongs_to_many actions clear the query cache. Closes #10840 [john.andrews]
* Fix issue where Table#references doesn't pass a :null option to a *_type attribute for polymorphic associations. Closes #10753 [railsjitsu]
View
24 activerecord/lib/active_record/associations/association_collection.rb
@@ -43,8 +43,8 @@ def delete_all
end
# Calculate sum using SQL, not Enumerable
- def sum(*args, &block)
- calculate(:sum, *args, &block)
+ def sum(*args)
+ calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? }
end
# Remove +records+ from this association. Does not destroy +records+.
@@ -121,9 +121,9 @@ def empty?
size.zero?
end
- def any?(&block)
+ def any?
if block_given?
- method_missing(:any?, &block)
+ method_missing(:any?) { |*block_args| yield(*block_args) if block_given? }
else
!empty?
end
@@ -157,11 +157,13 @@ def replace(other_array)
protected
- def method_missing(method, *args, &block)
+ def method_missing(method, *args)
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
- super
+ super { |*block_args| yield(*block_args) if block_given? }
else
- @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) }
+ @reflection.klass.send(:with_scope, construct_scope) {
+ @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? }
+ }
end
end
@@ -187,15 +189,15 @@ def find_target
private
- def create_record(attrs, &block)
+ def create_record(attrs)
ensure_owner_is_not_new
record = @reflection.klass.send(:with_scope, :create => construct_scope[:create]) { @reflection.klass.new(attrs) }
- add_record_to_target_with_callbacks(record, &block)
+ add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? }
end
- def build_record(attrs, &block)
+ def build_record(attrs)
record = @reflection.klass.new(attrs)
- add_record_to_target_with_callbacks(record, &block)
+ add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? }
end
def add_record_to_target_with_callbacks(record)
View
10 activerecord/lib/active_record/associations/association_proxy.rb
@@ -78,6 +78,12 @@ def inspect
@target.inspect
end
+ def to_xml(options={}, &block)
+ if load_target
+ @target.to_xml(options, &block)
+ end
+ end
+
protected
def dependent?
@reflection.options[:dependent]
@@ -120,9 +126,9 @@ def merge_options_from_reflection!(options)
end
private
- def method_missing(method, *args, &block)
+ def method_missing(method, *args)
if load_target
- @target.send(method, *args, &block)
+ @target.send(method, *args) { |*block_args| yield(*block_args) if block_given? }
end
end
View
12 activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -113,8 +113,8 @@ def size
end
# Calculate sum using SQL, not Enumerable
- def sum(*args, &block)
- calculate(:sum, *args, &block)
+ def sum(*args)
+ calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? }
end
def count(*args)
@@ -128,11 +128,13 @@ def count(*args)
end
protected
- def method_missing(method, *args, &block)
+ def method_missing(method, *args)
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
- super
+ super { |*block_args| yield(*block_args) if block_given? }
else
- @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) }
+ @reflection.klass.send(:with_scope, construct_scope) {
+ @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? }
+ }
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.