couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r680796 - in /incubator/couchdb/trunk: share/www/script/couch_tests.js src/couchdb/couch_btree.erl src/couchdb/couch_httpd.erl
Date Tue, 29 Jul 2008 18:23:43 GMT
Author: damien
Date: Tue Jul 29 11:23:42 2008
New Revision: 680796

URL: http://svn.apache.org/viewvc?rev=680796&view=rev
Log:
Fix for problem with count query arg in grouped reduce views. Previous fix would keep enumerating
over subsequent view results despite not returning them.

Modified:
    incubator/couchdb/trunk/share/www/script/couch_tests.js
    incubator/couchdb/trunk/src/couchdb/couch_btree.erl
    incubator/couchdb/trunk/src/couchdb/couch_httpd.erl

Modified: incubator/couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/script/couch_tests.js?rev=680796&r1=680795&r2=680796&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ incubator/couchdb/trunk/share/www/script/couch_tests.js [utf-8] Tue Jul 29 11:23:42 2008
@@ -290,6 +290,12 @@
     result = db.query(map, reduce, {startkey: 4, endkey: 6});
     T(result.rows[0].value == 15);
 
+    result = db.query(map, reduce, {group:true, count:3});
+    T(result.rows.length == 3);
+    T(result.rows[0].value == 1);
+    T(result.rows[1].value == 2);
+    T(result.rows[2].value == 3);
+
     for(var i=1; i<numDocs/2; i+=30) {
       result = db.query(map, reduce, {startkey: i, endkey: numDocs - i});
       T(result.rows[0].value == summate(numDocs-i) - summate(i-1));

Modified: incubator/couchdb/trunk/src/couchdb/couch_btree.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_btree.erl?rev=680796&r1=680795&r2=680796&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_btree.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_btree.erl Tue Jul 29 11:23:42 2008
@@ -78,17 +78,20 @@
         rev -> {EndKey, StartKey};
         fwd -> {StartKey, EndKey}
     end,
-    {ok, Acc2, GroupedRedsAcc2, GroupedKVsAcc2, GroupedKey2} =
-        reduce_stream_node(Bt, Dir, Root, StartKey2, EndKey2, nil, [], [],
-        KeyGroupFun, Fun, Acc),
-    if GroupedKey2 == nil ->
-        {ok, Acc2};
-    true ->
-        case (catch Fun(GroupedKey2, {GroupedKVsAcc2, GroupedRedsAcc2}, Acc2)) of
+    try
+        {ok, Acc2, GroupedRedsAcc2, GroupedKVsAcc2, GroupedKey2} =
+            reduce_stream_node(Bt, Dir, Root, StartKey2, EndKey2, nil, [], [],
+            KeyGroupFun, Fun, Acc),
+        if GroupedKey2 == nil ->
+            {ok, Acc2};
+        true ->
+            case Fun(GroupedKey2, {GroupedKVsAcc2, GroupedRedsAcc2}, Acc2) of
             {ok, Acc3} -> {ok, Acc3};
-            {stop, Acc3} -> {ok, Acc3};
-            Else -> throw(Else)
+            {stop, Acc3} -> {ok, Acc3}
+            end
         end
+    catch
+        throw:{stop, AccDone} -> {ok, AccDone}
     end.
 
 full_reduce(#btree{root=nil,reduce=Reduce}) ->

Modified: incubator/couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=680796&r1=680795&r2=680796&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_httpd.erl Tue Jul 29 11:23:42 2008
@@ -465,7 +465,7 @@
         fun(_Key, _Red, {AccSeparator,AccSkip,AccCount}) when AccSkip > 0 ->
             {ok, {AccSeparator,AccSkip-1,AccCount}};
         (_Key, _Red, {AccSeparator,0,AccCount}) when AccCount == 0 ->
-            {ok, {AccSeparator,0,AccCount}};
+            {stop, {AccSeparator,0,AccCount}};
         (_Key, Red, {AccSeparator,0,AccCount}) when GroupLevel == 0 ->
             Json = lists:flatten(cjson:encode({obj, [{key, null}, {value, Red}]})),
             Resp:write_chunk(AccSeparator ++ Json),



Mime
View raw message