Permalink
Browse files

Perf fix - Use an instance variable instead of a class_attribute. Tha…

…nks @josevalim and @jhawthorn for the prompting.
  • Loading branch information...
1 parent f24d8fa commit 1cc0c3f52ca1aaaa968bd6f5ed6834fd9b99adce @jonleighton jonleighton committed Jun 16, 2011
Showing with 4 additions and 8 deletions.
  1. +4 −8 activerecord/lib/active_record/base.rb
@@ -428,10 +428,6 @@ class Base
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
@@ -1266,11 +1262,11 @@ def default_scope(scope = {})
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
@@ -1286,7 +1282,7 @@ def build_default_scope #:nodoc:
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

0 comments on commit 1cc0c3f

Please sign in to comment.