From 7a9a4f4e7bd090fd27e05b03f93832d79f5f8db2 Mon Sep 17 00:00:00 2001 From: jessib Date: Fri, 7 Dec 2012 15:38:23 -0800 Subject: Added reduce functions, so pagination should now work correctly. This also removes the need for .all call in some tests. --- help/app/models/ticket.rb | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'help/app/models/ticket.rb') diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb index f9852a4..cd4fcfb 100644 --- a/help/app/models/ticket.rb +++ b/help/app/models/ticket.rb @@ -56,11 +56,11 @@ class Ticket < CouchRest::Model::Base if (comment.posted_by && !arr[comment.posted_by]) { //don't add duplicates arr[comment.posted_by] = true; - emit(comment.posted_by, doc); + emit(comment.posted_by, 1); } }); } - }" + }", :reduce => "function(k,v,r) { return sum(v); }" view :includes_post_by_and_open_status_and_updated_at, :map => @@ -71,12 +71,11 @@ class Ticket < CouchRest::Model::Base if (comment.posted_by && !arr[comment.posted_by]) { //don't add duplicates arr[comment.posted_by] = true; - emit([comment.posted_by, doc.is_open, doc.updated_at], doc); + emit([comment.posted_by, doc.is_open, doc.updated_at], 1); } }); } - }" - + }", :reduce => "function(k,v,r) { return sum(v); }" view :includes_post_by_and_open_status_and_created_at, :map => @@ -87,11 +86,11 @@ class Ticket < CouchRest::Model::Base if (comment.posted_by && !arr[comment.posted_by]) { //don't add duplicates arr[comment.posted_by] = true; - emit([comment.posted_by, doc.is_open, doc.created_at], doc); + emit([comment.posted_by, doc.is_open, doc.created_at], 1); } }); } - }" + }", :reduce => "function(k,v,r) { return sum(v); }" view :includes_post_by_and_updated_at, :map => @@ -102,11 +101,11 @@ class Ticket < CouchRest::Model::Base if (comment.posted_by && !arr[comment.posted_by]) { //don't add duplicates arr[comment.posted_by] = true; - emit([comment.posted_by, doc.updated_at], doc); + emit([comment.posted_by, doc.updated_at], 1); } }); } - }" + }", :reduce => "function(k,v,r) { return sum(v); }" view :includes_post_by_and_created_at, @@ -118,11 +117,11 @@ class Ticket < CouchRest::Model::Base if (comment.posted_by && !arr[comment.posted_by]) { //don't add duplicates arr[comment.posted_by] = true; - emit([comment.posted_by, doc.created_at], doc); + emit([comment.posted_by, doc.created_at], 1); } }); } - }" + }", :reduce => "function(k,v,r) { return sum(v); }" end -- cgit v1.2.3