From be99ae78c9c4b52541297f0fb146701070041c02 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Thu, 16 Jun 2011 21:12:47 +0100 Subject: Perf fix - Use an instance variable instead of a class_attribute. Thanks @josevalim and @jhawthorn for the prompting. --- activerecord/lib/active_record/base.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 08cccf1da2..6a5d282973 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -428,10 +428,6 @@ module ActiveRecord #:nodoc: class_attribute :default_scopes, :instance_writer => false self.default_scopes = [] - # Boolean flag to prevent infinite recursion when evaluating default scopes - class_attribute :apply_default_scope, :instance_writer => false - self.apply_default_scope = true - # Returns a hash of all the attributes that have been specified for serialization as # keys and their class restriction as values. class_attribute :serialized_attributes @@ -1265,11 +1261,11 @@ MSG self.default_scopes = default_scopes + [scope] end - # The apply_default_scope flag is used to prevent an infinite recursion situation where + # The @ignore_default_scope flag is used to prevent an infinite recursion situation where # a default scope references a scope which has a default scope which references a scope... def build_default_scope #:nodoc: - return unless apply_default_scope - self.apply_default_scope = false + return if defined?(@ignore_default_scope) && @ignore_default_scope + @ignore_default_scope = true if method(:default_scope).owner != Base.singleton_class default_scope @@ -1285,7 +1281,7 @@ MSG end end ensure - self.apply_default_scope = true + @ignore_default_scope = false end # Returns the class type of the record using the current module as a prefix. So descendants of -- cgit v1.2.3