mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
make a singleton for AssociationScope
AssociationScope no longer maintains state, so we're safe to keep a singleton and save on GC time
This commit is contained in:
parent
8e6ef92fd9
commit
213b2fbf40
3 changed files with 8 additions and 3 deletions
|
@ -94,7 +94,7 @@ module ActiveRecord
|
|||
# actually gets built.
|
||||
def association_scope
|
||||
if klass
|
||||
@association_scope ||= AssociationScope.new.scope(self, klass.connection)
|
||||
@association_scope ||= AssociationScope.scope(self, klass.connection)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
module ActiveRecord
|
||||
module Associations
|
||||
class AssociationScope #:nodoc:
|
||||
INSTANCE = new
|
||||
|
||||
def self.scope(association, connection)
|
||||
INSTANCE.scope association, connection
|
||||
end
|
||||
|
||||
def scope(association, connection)
|
||||
klass = association.klass
|
||||
reflection = association.reflection
|
||||
|
|
|
@ -6,8 +6,7 @@ module ActiveRecord
|
|||
module Associations
|
||||
class AssociationScopeTest < ActiveRecord::TestCase
|
||||
test 'does not duplicate conditions' do
|
||||
association_scope = AssociationScope.new
|
||||
scope = association_scope.scope(Author.new.association(:welcome_posts),
|
||||
scope = AssociationScope.scope(Author.new.association(:welcome_posts),
|
||||
Author.connection)
|
||||
wheres = scope.where_values.map(&:right)
|
||||
assert_equal wheres.uniq, wheres
|
||||
|
|
Loading…
Reference in a new issue