Permalink
Browse files

Use key streaming for count, now that it works right over HTTP.

  • Loading branch information...
1 parent 25ba9fc commit f9b022c2e5d5c403efbcb2bc09eeb8d17b60e1d6 Kyle Kingsbury committed Apr 26, 2011
Showing with 7 additions and 16 deletions.
  1. +7 −16 lib/risky.rb
View
@@ -84,22 +84,13 @@ def self.cast(data)
casted
end
- # Counts the number of models via MR
- def self.count
- map("
- function(v) {
- return [1];
- };
- ").reduce("
- function(counts, arg) {
- return [
- counts.reduce(
- function(acc, value) {
- return acc + value
- }, 0)
- ];
- }
- ", :keep => true).run.first
+ # Counts the number of values in the bucket via key streaming
+ def self.count(opts = {:reload => true})
+ count = 0
+ bucket.keys(opts) do |keys|
+ count += keys.length
+ end
+ count
end
# Returns true when record deleted.

0 comments on commit f9b022c

Please sign in to comment.