Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make a singleton for AssociationScope

AssociationScope no longer maintains state, so we're safe to keep a
singleton and save on GC time
  • Loading branch information...
commit 213b2fbf40f6a1ce8381749bd5ba734f20bd4b21 1 parent 8e6ef92
Aaron Patterson tenderlove authored
2  activerecord/lib/active_record/associations/association.rb
View
@@ -94,7 +94,7 @@ def scope
# 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
6 activerecord/lib/active_record/associations/association_scope.rb
View
@@ -1,6 +1,12 @@
module ActiveRecord
module Associations
class AssociationScope #:nodoc:
+ INSTANCE = new
+
+ def self.scope(association, connection)
Arthur Nogueira Neves Collaborator

maybe we need a mutex around this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ INSTANCE.scope association, connection
+ end
+
def scope(association, connection)
klass = association.klass
reflection = association.reflection
3  activerecord/test/cases/associations/association_scope_test.rb
View
@@ -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
Arthur Nogueira Neves

maybe we need a mutex around this?

Please sign in to comment.
Something went wrong with that request. Please try again.