couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r744240 - in /couchdb/trunk: share/www/script/couch_tests.js src/couchdb/couch_db.hrl src/couchdb/couch_httpd_external.erl src/couchdb/couch_httpd_show.erl src/couchdb/couch_httpd_view.erl
Date Fri, 13 Feb 2009 20:52:29 GMT
Author: jchris
Date: Fri Feb 13 20:52:28 2009
New Revision: 744240

URL: http://svn.apache.org/viewvc?rev=744240&view=rev
Log:
apply COUCHDB-252.
Allow _list functions to signal that iteration of the view should cease.
Thanks davisp.

Modified:
    couchdb/trunk/share/www/script/couch_tests.js
    couchdb/trunk/src/couchdb/couch_db.hrl
    couchdb/trunk/src/couchdb/couch_httpd_external.erl
    couchdb/trunk/src/couchdb/couch_httpd_show.erl
    couchdb/trunk/src/couchdb/couch_httpd_view.erl

Modified: couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch_tests.js?rev=744240&r1=744239&r2=744240&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/couch_tests.js [utf-8] Fri Feb 13 20:52:28 2009
@@ -2796,9 +2796,33 @@
             }
           })
         }),
-        qsParams: stringFun(function(head, row, req, row_number) {
+        qsParams: stringFun(function(head, row, req, row_info) {
           if(head) return {body: req.query.foo};
           else return {body: "\n"};
+        }),
+        stopIter: stringFun(function(head, row, req, row_info) {
+          if(head) {
+            return {body: "head"};
+          } else if(row) {
+            if(row_info.row_number > 2) return {stop: true};
+            return {body: " " + row_info.row_number};
+          } else {
+            return {body: " tail"};
+          }
+        }),
+        stopIter2: stringFun(function(head, row, req, row_info) {
+          return respondWith(req, {
+            html: function() {
+              if(head) {
+                return "head";
+              } else if(row) {
+                if(row_info.row_number > 2) return {stop: true};
+                return " " + row_info.row_number;
+              } else {
+                return " tail";
+              }
+            }
+          });
         })
       }
     };
@@ -2870,6 +2894,15 @@
     // now with extra qs params
     xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/qsParams/basicView?foo=blam");
     T(xhr.responseText.match(/blam/));
+    
+
+    // aborting iteration
+    xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/stopIter/basicView");
+    T(xhr.responseText.match(/^head 0 1 2 tail$/));
+    xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/stopIter2/basicView");
+    T(xhr.responseText.match(/^head 0 1 2 tail$/));
+
+
   },
 
   compact: function(debug) {

Modified: couchdb/trunk/src/couchdb/couch_db.hrl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_db.hrl?rev=744240&r1=744239&r2=744240&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_db.hrl (original)
+++ couchdb/trunk/src/couchdb/couch_db.hrl Fri Feb 13 20:52:28 2009
@@ -162,6 +162,7 @@
 
 -record(extern_resp_args, {
     code = 200,
+    stop = false,
     data = <<>>,
     ctype = "application/json",
     headers = []

Modified: couchdb/trunk/src/couchdb/couch_httpd_external.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_external.erl?rev=744240&r1=744239&r2=744240&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_external.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_external.erl Fri Feb 13 20:52:28 2009
@@ -106,6 +106,8 @@
                 Args;
             {<<"code">>, Value} ->
                 Args#extern_resp_args{code=Value};
+            {<<"stop">>, true} ->
+                Args#extern_resp_args{stop=true};
             {<<"json">>, Value} ->
                 Args#extern_resp_args{
                     data=?JSON_ENCODE(Value),

Modified: couchdb/trunk/src/couchdb/couch_httpd_show.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_show.erl?rev=744240&r1=744239&r2=744240&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_show.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_show.erl Fri Feb 13 20:52:28 2009
@@ -127,13 +127,17 @@
         JsonResp = couch_query_servers:render_list_row(QueryServer, 
             Req, Db2, {{Key, DocId}, Value}),
         #extern_resp_args{
+            stop = StopIter,
             data = RowBody
         } = couch_httpd_external:parse_external_response(JsonResp),
         RowFront2 = case RowFront of
         nil -> [];
         _ -> RowFront
         end,
-        send_chunk(Resp, RowFront2 ++ binary_to_list(RowBody))
+        case StopIter of
+        true -> stop;
+        _ -> send_chunk(Resp, RowFront2 ++ binary_to_list(RowBody))
+        end
     end,
     
     FoldlFun = couch_httpd_view:make_view_fold_fun(Req, QueryArgs, Db, RowCount,

Modified: couchdb/trunk/src/couchdb/couch_httpd_view.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_view.erl?rev=744240&r1=744239&r2=744240&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_view.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_view.erl Fri Feb 13 20:52:28 2009
@@ -416,13 +416,17 @@
             Offset = ReduceCountFun(OffsetReds),
             {ok, Resp2, BeginBody} = StartRespFun(Req, 200, 
                 TotalViewCount, Offset),
-            SendRowFun(Resp2, Db, 
-                {{Key, DocId}, Value}, BeginBody, IncludeDocs),
-            {ok, {AccLimit - 1, 0, Resp2, AccRevRows}};
+            case SendRowFun(Resp2, Db, 
+                {{Key, DocId}, Value}, BeginBody, IncludeDocs) of
+            stop ->  {stop, {AccLimit - 1, 0, Resp2, AccRevRows}};
+            _ -> {ok, {AccLimit - 1, 0, Resp2, AccRevRows}}
+            end;
         {_, AccLimit, _, Resp} when (AccLimit > 0) ->
-            SendRowFun(Resp, Db, 
-                {{Key, DocId}, Value}, nil, IncludeDocs),
-            {ok, {AccLimit - 1, 0, Resp, AccRevRows}}
+            case SendRowFun(Resp, Db, 
+                {{Key, DocId}, Value}, nil, IncludeDocs) of
+            stop ->  {stop, {AccLimit - 1, 0, Resp, AccRevRows}};
+            _ -> {ok, {AccLimit - 1, 0, Resp, AccRevRows}}
+            end
         end
     end.
 



Mime
View raw message