You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2017/03/01 16:37:47 UTC

[13/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24

Send empty string from _list if no result

There is a corner case when list function does not return any Chunk.
In this case we would want to return empty string to the client.

COUCHDB-2847


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/f9a58d89
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/f9a58d89
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/f9a58d89

Branch: refs/heads/2971-count-distinct
Commit: f9a58d891daba03556a19d6bc10176bcd6e587e3
Parents: 8567b43
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Fri Jun 17 16:09:50 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Fri Jun 17 16:09:50 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_show.erl | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/f9a58d89/src/couch_mrview_show.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_show.erl b/src/couch_mrview_show.erl
index 5a01b84..f7e0f56 100644
--- a/src/couch_mrview_show.erl
+++ b/src/couch_mrview_show.erl
@@ -227,7 +227,7 @@ list_cb({row, Row}, #lacc{code=undefined} = Acc) ->
 list_cb({row, Row}, Acc) ->
     send_list_row(Row, Acc);
 list_cb(complete, Acc) ->
-    #lacc{qserver = {Proc, _}, resp = Resp0} = Acc,
+    #lacc{qserver = {Proc, _}, req = Req, resp = Resp0} = Acc,
     if Resp0 =:= nil ->
         {ok, #lacc{resp = Resp}} = start_list_resp({[]}, Acc);
     true ->
@@ -240,7 +240,7 @@ list_cb(complete, Acc) ->
         [<<"end">>, Data] ->
             #lacc{resp = Resp2} = send_non_empty_chunk(Acc#lacc{resp=Resp}, Data)
     end,
-    last_chunk(Resp2),
+    last_chunk(Req, Resp2),
     {ok, Resp2}.
 
 start_list_resp(Head, Acc) ->
@@ -262,7 +262,7 @@ fixup_headers(Headers, #lacc{etag=ETag} = Acc) ->
     Headers3 = chttpd_external:default_or_content_type(CType, ExtHeaders),
     Acc#lacc{code=Code, headers=Headers3}.
 
-send_list_row(Row, #lacc{qserver = {Proc, _}, resp = Resp} = Acc) ->
+send_list_row(Row, #lacc{qserver = {Proc, _}, req = Req, resp = Resp} = Acc) ->
     RowObj = case couch_util:get_value(id, Row) of
         undefined -> [];
         Id -> [{id, Id}]
@@ -286,12 +286,12 @@ send_list_row(Row, #lacc{qserver = {Proc, _}, resp = Resp} = Acc) ->
     [<<"end">>, Chunk, Headers] ->
         Acc2 = send_non_empty_chunk(fixup_headers(Headers, Acc), Chunk),
         #lacc{resp = Resp2} = Acc2,
-        last_chunk(Resp2),
+        last_chunk(Req, Resp2),
         {stop, Acc2};
     [<<"end">>, Chunk] ->
         Acc2 = send_non_empty_chunk(Acc, Chunk),
         #lacc{resp = Resp2} = Acc2,
-        last_chunk(Resp2),
+        last_chunk(Req, Resp2),
         {stop, Acc2}
     catch Error ->
         case Resp of
@@ -372,7 +372,9 @@ json_req_obj(Req, Db) ->
     spawn_monitor(fun() -> exit(chttpd_external:json_req_obj(Req, Db)) end),
     receive {'DOWN', _, _, _, JsonReq} -> JsonReq end.
 
-last_chunk(Resp) ->
+last_chunk(Req, undefined) ->
+    chttpd:send_response(Req, 200, [], <<"">>);
+last_chunk(_Req, Resp) ->
     chttpd:send_chunk(Resp, []).