You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2014/02/08 00:16:35 UTC
[2/2] couch-mrview commit: updated
refs/heads/1993-bigcouch-couch-mrview to 2497d52
Expose callbacks and switch to chttpd delayed response
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/2497d524
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/2497d524
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/2497d524
Branch: refs/heads/1993-bigcouch-couch-mrview
Commit: 2497d524fd7a88ed40c6006bd68769054e2aae51
Parents: 373e147
Author: Russell Branca <ch...@gmail.com>
Authored: Fri Feb 7 14:52:17 2014 -0800
Committer: Russell Branca <ch...@gmail.com>
Committed: Fri Feb 7 14:52:17 2014 -0800
----------------------------------------------------------------------
src/couch_mrview_http.erl | 46 +++++++++++++++++++++++++-----------------
1 file changed, 28 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/2497d524/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 940bfa0..8740003 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -19,7 +19,11 @@
handle_info_req/3,
handle_compact_req/3,
handle_cleanup_req/2,
- parse_qs/2
+ parse_qs/2,
+ view_cb/2,
+ row_to_json/1,
+ row_to_json/2,
+ check_view_etag/3
]).
@@ -128,11 +132,7 @@ do_all_docs_req(Req, Db, Keys) ->
design_doc_view(Req, Db, DDoc, ViewName, Keys) ->
Args0 = parse_qs(Req, Keys),
ETagFun = fun(Sig, Acc0) ->
- ETag = couch_httpd:make_etag(Sig),
- case couch_httpd:etag_match(Req, ETag) of
- true -> throw({etag_match, ETag});
- false -> {ok, Acc0#vacc{etag=ETag}}
- end
+ check_view_etag(Sig, Acc0, Req)
end,
Args = Args0#mrargs{preflight_fun=ETagFun},
{ok, Resp} = couch_httpd:etag_maybe(Req, fun() ->
@@ -147,7 +147,7 @@ design_doc_view(Req, Db, DDoc, ViewName, Keys) ->
view_cb({meta, Meta}, #vacc{resp=undefined}=Acc) ->
Headers = [{"ETag", Acc#vacc.etag}],
- {ok, Resp} = couch_httpd:start_json_response(Acc#vacc.req, 200, Headers),
+ {ok, Resp} = chttpd:start_delayed_json_response(Acc#vacc.req, 200, Headers),
% Map function starting
Parts = case couch_util:get_value(total, Meta) of
undefined -> [];
@@ -160,26 +160,28 @@ view_cb({meta, Meta}, #vacc{resp=undefined}=Acc) ->
UpdateSeq -> [io_lib:format("\"update_seq\":~p", [UpdateSeq])]
end ++ ["\"rows\":["],
Chunk = lists:flatten("{" ++ string:join(Parts, ",") ++ "\r\n"),
- couch_httpd:send_chunk(Resp, Chunk),
- {ok, Acc#vacc{resp=Resp, prepend=""}};
+ {ok, Resp1} = chttpd:send_delayed_chunk(Resp, Chunk),
+ {ok, Acc#vacc{resp=Resp1, prepend=""}};
view_cb({row, Row}, #vacc{resp=undefined}=Acc) ->
% Reduce function starting
Headers = [{"ETag", Acc#vacc.etag}],
- {ok, Resp} = couch_httpd:start_json_response(Acc#vacc.req, 200, Headers),
- couch_httpd:send_chunk(Resp, ["{\"rows\":[\r\n", row_to_json(Row)]),
- {ok, #vacc{resp=Resp, prepend=",\r\n"}};
+ {ok, Resp} = chttpd:start_delayed_json_response(Acc#vacc.req, 200, Headers),
+ Chunk = ["{\"rows\":[\r\n", row_to_json(Row)],
+ {ok, Resp1} = chttpd:send_delayed_chunk(Resp, Chunk),
+ {ok, #vacc{resp=Resp1, prepend=",\r\n"}};
view_cb({row, Row}, Acc) ->
% Adding another row
- couch_httpd:send_chunk(Acc#vacc.resp, [Acc#vacc.prepend, row_to_json(Row)]),
- {ok, Acc#vacc{prepend=",\r\n"}};
+ Chunk = [Acc#vacc.prepend, row_to_json(Row)],
+ {ok, Resp1} = chttpd:send_delayed_chunk(Acc#vacc.resp, Chunk),
+ {ok, Acc#vacc{prepend=",\r\n", resp=Resp1}};
view_cb(complete, #vacc{resp=undefined}=Acc) ->
% Nothing in view
- {ok, Resp} = couch_httpd:send_json(Acc#vacc.req, 200, {[{rows, []}]}),
+ {ok, Resp} = chttpd:send_json(Acc#vacc.req, 200, {[{rows, []}]}),
{ok, Acc#vacc{resp=Resp}};
-view_cb(complete, Acc) ->
+view_cb(complete, #vacc{resp=Resp}=Acc) ->
% Finish view output
- couch_httpd:send_chunk(Acc#vacc.resp, "\r\n]}"),
- couch_httpd:end_json_response(Acc#vacc.resp),
+ chttpd:send_delayed_chunk(Resp, "\r\n]}"),
+ chttpd:end_delayed_json_response(Resp),
{ok, Acc}.
@@ -328,3 +330,11 @@ parse_pos_int(Val) ->
Msg = io_lib:format(Fmt, [Val]),
throw({query_parse_error, ?l2b(Msg)})
end.
+
+
+check_view_etag(Sig, Acc0, Req) ->
+ ETag = couch_httpd:make_etag(Sig),
+ case couch_httpd:etag_match(Req, ETag) of
+ true -> throw({etag_match, ETag});
+ false -> {ok, Acc0#vacc{etag=ETag}}
+ end.