Permalink
Browse files

speed up the collection proxy reader method, but slow down the constr…

…uctor
  • Loading branch information...
1 parent 9ec42f9 commit f9e4c3c7c0c4152b62fe9202a9d12262884bb118 @tenderlove tenderlove committed Feb 13, 2014
Showing with 5 additions and 1 deletion.
  1. +5 −1 activerecord/lib/active_record/associations/collection_association.rb
View
6 activerecord/lib/active_record/associations/collection_association.rb
@@ -24,6 +24,10 @@ module Associations
# If you need to work on all current children, new and existing records,
# +load_target+ and the +loaded+ flag are your friends.
class CollectionAssociation < Association #:nodoc:
+ def initialize(owner, reflection)
+ super
+ @proxy = CollectionProxy.create(klass, self)
+ end
# Implements the reader method, e.g. foo.items for Foo.has_many :items
def reader(force_reload = false)
@@ -33,7 +37,7 @@ def reader(force_reload = false)
reload
end
- @proxy ||= CollectionProxy.create(klass, self)
+ @proxy
end
# Implements the writer method, e.g. foo.items= for Foo.has_many :items

1 comment on commit f9e4c3c

@arthurnn
Ruby on Rails member

seems like this commit caused this regression #14116 . I would revert this, as this optimization didnt make a big difference anyhow.

Please sign in to comment.