Repository: couchdb-chttpd Updated Branches: refs/heads/1993-bigcouch-couch-mrview 059a03ab4 -> 19020f984
WIP: switch to using couch_mrview list functions Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/19020f98 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/19020f98 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/19020f98 Branch: refs/heads/1993-bigcouch-couch-mrview Commit: 19020f984d44ae0c349736f5f9573e9e518f2571 Parents: 059a03a Author: Russell Branca <[email protected]> Authored: Sun Mar 16 09:57:16 2014 -0700 Committer: Russell Branca <[email protected]> Committed: Sun Mar 16 09:57:16 2014 -0700 ---------------------------------------------------------------------- src/chttpd_show.erl | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/19020f98/src/chttpd_show.erl ---------------------------------------------------------------------- diff --git a/src/chttpd_show.erl b/src/chttpd_show.erl index b028f4c..3996a7a 100644 --- a/src/chttpd_show.erl +++ b/src/chttpd_show.erl @@ -17,12 +17,14 @@ -include_lib("couch/include/couch_db.hrl"). -record(lacc, { + db, req, - resp = nil, + resp, qserver, lname, - db, - etag + etag, + code, + headers }). % /db/_design/foo/_show/bar/docid @@ -152,13 +154,13 @@ send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId) -> % view-list request with view and list from same design doc. handle_view_list_req(#httpd{method='GET', path_parts=[_, _, DesignName, _, ListName, ViewName]}=Req, Db, DDoc) -> - Keys = chttpd:qs_json_value(Req, "keys", nil), + Keys = chttpd:qs_json_value(Req, "keys", undefined), handle_view_list(Req, Db, DDoc, ListName, {DesignName, ViewName}, Keys); % view-list request with view and list from different design docs. handle_view_list_req(#httpd{method='GET', path_parts=[_, _, _, _, ListName, DesignName, ViewName]}=Req, Db, DDoc) -> - Keys = chttpd:qs_json_value(Req, "keys", nil), + Keys = chttpd:qs_json_value(Req, "keys", undefined), handle_view_list(Req, Db, DDoc, ListName, {DesignName, ViewName}, Keys); handle_view_list_req(#httpd{method='GET'}=Req, _Db, _DDoc) -> @@ -168,7 +170,7 @@ handle_view_list_req(#httpd{method='POST', path_parts=[_, _, DesignName, _, ListName, ViewName]}=Req, Db, DDoc) -> ReqBody = chttpd:body(Req), {Props2} = ?JSON_DECODE(ReqBody), - Keys = proplists:get_value(<<"keys">>, Props2, nil), + Keys = proplists:get_value(<<"keys">>, Props2, undefined), handle_view_list(Req#httpd{req_body=ReqBody}, Db, DDoc, ListName, {DesignName, ViewName}, Keys); @@ -176,7 +178,7 @@ handle_view_list_req(#httpd{method='POST', path_parts=[_, _, _, _, ListName, DesignName, ViewName]}=Req, Db, DDoc) -> ReqBody = chttpd:body(Req), {Props2} = ?JSON_DECODE(ReqBody), - Keys = proplists:get_value(<<"keys">>, Props2, nil), + Keys = proplists:get_value(<<"keys">>, Props2, undefined), handle_view_list(Req#httpd{req_body=ReqBody}, Db, DDoc, ListName, {DesignName, ViewName}, Keys); @@ -189,14 +191,10 @@ handle_view_list_req(Req, _Db, _DDoc) -> handle_view_list(Req, Db, DDoc, LName, {ViewDesignName, ViewName}, Keys) -> %% Will throw an exception if the _list handler is missing couch_util:get_nested_json_value(DDoc#doc.body, [<<"lists">>, LName]), - {ok, VDoc} = fabric:open_doc(Db, <<"_design/", ViewDesignName/binary>>, []), - Group = couch_view_group:design_doc_to_view_group(VDoc), - IsReduce = chttpd_view:get_reduce_type(Req), - ViewType = chttpd_view:extract_view_type(ViewName, - couch_view_group:get_views(Group), IsReduce), - QueryArgs = chttpd_view:parse_view_params(Req, Keys, ViewType), + {ok, VDoc} = ddoc_cache:open(Db#db.name, <<"_design/", ViewDesignName/binary>>), CB = fun list_callback/2, Etag = couch_uuids:new(), + QueryArgs = couch_mrview_http:parse_params(Req, Keys), chttpd:etag_respond(Req, Etag, fun() -> couch_query_servers:with_ddoc_proc(DDoc, fun(QServer) -> Acc0 = #lacc{ @@ -210,9 +208,19 @@ handle_view_list(Req, Db, DDoc, LName, {ViewDesignName, ViewName}, Keys) -> end) end). -list_callback({total_and_offset, Total, Offset}, #lacc{resp=nil} = Acc) -> - start_list_resp({[{<<"total_rows">>, Total}, {<<"offset">>, Offset}]}, Acc); -list_callback({total_and_offset, _, _}, Acc) -> +list_callback({meta, Meta}, #lacc{resp=nil} = Acc) -> + MetaProps = case couch_util:get_value(total, Meta) of + undefined -> []; + Total -> [{total_rows, Total}] + end ++ case couch_util:get_value(offset, Meta) of + undefined -> []; + Offset -> [{offset, Offset}] + end ++ case couch_util:get_value(update_seq, Meta) of + undefined -> []; + UpdateSeq -> [{update_seq, UpdateSeq}] + end, + start_list_resp({MetaProps}, Acc); +list_callback({meta, []}, Acc) -> % a sorted=false view where the message came in late. Ignore. {ok, Acc}; list_callback({row, Row}, #lacc{resp=nil} = Acc) -> @@ -267,7 +275,7 @@ start_list_resp(Head, Acc) -> {ok, Acc#lacc{resp=Resp}}. send_list_row(Row, #lacc{qserver = {Proc, _}, resp = Resp} = Acc) -> - try couch_query_servers:proc_prompt(Proc, [<<"list_row">>, Row]) of + try couch_query_servers:proc_prompt(Proc, [<<"list_row">>, {Row}]) of [<<"chunks">>, Chunk] -> {ok, Resp1} = send_non_empty_chunk(Resp, Chunk), {ok, Acc#lacc{resp=Resp1}};
