Skip to content

Commit

Permalink
Fixing count memoization
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Nov 28, 2009
1 parent b16da83 commit e8aaebf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/mongoid/criteria.rb
Expand Up @@ -31,7 +31,7 @@ def ==(other)
when Criteria
self.selector == other.selector && self.options == other.options
when Enumerable
execute
@collection ||= execute
return (@collection == other)
else
return false
Expand Down Expand Up @@ -83,7 +83,7 @@ def all(selections = {})
def count
return @count if @count
@klass = klass if klass
return @klass.collection.find(@selector, @options.dup).count
@count ||= @klass.collection.find(@selector, @options.dup).count
end

# Iterate over each +Document+ in the results. This can take an optional
Expand Down Expand Up @@ -464,9 +464,9 @@ def execute
attributes = @klass.collection.find(@selector, @options.dup)
if attributes
@count = attributes.count
@collection = attributes.collect { |doc| @klass.instantiate(doc) }
attributes.collect { |doc| @klass.instantiate(doc) }
else
@collection = []
[]
end
end

Expand Down

0 comments on commit e8aaebf

Please sign in to comment.