Optimized Model.count to run about 3x faster

This commit is contained in:
Matt Aimonetti 2009-07-16 20:38:15 -07:00
parent 8f8b5dc568
commit 964526193b
3 changed files with 3 additions and 7 deletions

View file

@ -19,9 +19,7 @@ module CouchRest
# equal to the name of the current class. Takes the standard set of
# CouchRest::Database#view options
def count(opts = {}, &block)
result = all({:reduce => true}.merge(opts), &block)['rows']
return 0 if result.empty?
result.first['value']
all({:raw => true, :limit => 0}.merge(opts), &block)['total_rows']
end
# Load the first document that have the "couchrest-type" field equal to