Optimized Model.count to run about 3x faster
This commit is contained in:
parent
8f8b5dc568
commit
964526193b
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
* Minor enhancements
|
* Minor enhancements
|
||||||
|
|
||||||
|
* Optimized Model.count to run about 3x faster (Matt Aimonetti)
|
||||||
* Added Float casting (Ryan Felton & Matt Aimonetti)
|
* Added Float casting (Ryan Felton & Matt Aimonetti)
|
||||||
|
|
||||||
== 0.30
|
== 0.30
|
||||||
|
|
|
@ -37,9 +37,6 @@ module CouchRest
|
||||||
if (doc['couchrest-type'] == '#{self.to_s}') {
|
if (doc['couchrest-type'] == '#{self.to_s}') {
|
||||||
emit(null,1);
|
emit(null,1);
|
||||||
}
|
}
|
||||||
}",
|
|
||||||
'reduce' => "function(keys, values) {
|
|
||||||
return sum(values);
|
|
||||||
}"
|
}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,7 @@ module CouchRest
|
||||||
# equal to the name of the current class. Takes the standard set of
|
# equal to the name of the current class. Takes the standard set of
|
||||||
# CouchRest::Database#view options
|
# CouchRest::Database#view options
|
||||||
def count(opts = {}, &block)
|
def count(opts = {}, &block)
|
||||||
result = all({:reduce => true}.merge(opts), &block)['rows']
|
all({:raw => true, :limit => 0}.merge(opts), &block)['total_rows']
|
||||||
return 0 if result.empty?
|
|
||||||
result.first['value']
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Load the first document that have the "couchrest-type" field equal to
|
# Load the first document that have the "couchrest-type" field equal to
|
||||||
|
|
Loading…
Reference in a new issue