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 19:32:17 UTC

chttpd commit: updated refs/heads/1993-bigcouch-couch-mrview to b2344bc

Updated Branches:
  refs/heads/1993-bigcouch-couch-mrview 92e4d99b5 -> b2344bce4


Switch to using couch_mrview_http for _all_docs callback


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

Branch: refs/heads/1993-bigcouch-couch-mrview
Commit: b2344bce49f5a7c73c97e7866a42d5ef2dc9df6d
Parents: 92e4d99
Author: Russell Branca <ch...@gmail.com>
Authored: Sat Feb 8 10:28:51 2014 -0800
Committer: Russell Branca <ch...@gmail.com>
Committed: Sat Feb 8 10:30:23 2014 -0800

----------------------------------------------------------------------
 src/chttpd_db.erl | 39 +++++++++++++++------------------------
 1 file changed, 15 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/b2344bce/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index d5aedb0..e3a2ce7 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -12,6 +12,7 @@
 
 -module(chttpd_db).
 -include_lib("couch/include/couch_db.hrl").
+-include_lib("couch_mrview/include/couch_mrview.hrl").
 
 -export([handle_request/1, handle_compact_req/2, handle_design_req/2,
     db_req/2, couch_doc_open/4,handle_changes_req/2,
@@ -477,30 +478,20 @@ db_req(#httpd{path_parts=[_, DocId | FileNameParts]}=Req, Db) ->
     db_attachment_req(Req, Db, DocId, FileNameParts).
 
 all_docs_view(Req, Db, Keys) ->
-    % measure the time required to generate the etag, see if it's worth it
-    T0 = os:timestamp(),
-    {ok, Info} = fabric:get_db_info(Db),
-    Etag = couch_httpd:make_etag(Info),
-    DeltaT = timer:now_diff(os:timestamp(), T0) / 1000,
-    couch_stats_collector:record({couchdb, dbinfo}, DeltaT),
-    QueryArgs = chttpd_view:parse_view_params(Req, Keys, map),
-    chttpd:etag_respond(Req, Etag, fun() ->
-        {ok, Resp} = chttpd:start_delayed_json_response(Req, 200, [{"Etag",Etag}]),
-        fabric:all_docs(Db, fun all_docs_callback/2, {nil, Resp}, QueryArgs)
-    end).
-
-all_docs_callback({total_and_offset, Total, Offset}, {_, Resp}) ->
-    Chunk = "{\"total_rows\":~p,\"offset\":~p,\"rows\":[\r\n",
-    {ok, Resp1} = chttpd:send_delayed_chunk(Resp, io_lib:format(Chunk, [Total, Offset])),
-    {ok, {"", Resp1}};
-all_docs_callback({row, Row}, {Prepend, Resp}) ->
-    {ok, Resp1} = chttpd:send_delayed_chunk(Resp, [Prepend, ?JSON_ENCODE({Row})]),
-    {ok, {",\r\n", Resp1}};
-all_docs_callback(complete, {_, Resp}) ->
-    {ok, Resp1} = chttpd:send_delayed_chunk(Resp, "\r\n]}"),
-    chttpd:end_delayed_json_response(Resp1);
-all_docs_callback({error, Reason}, {_, Resp}) ->
-    chttpd:send_delayed_error(Resp, Reason).
+    Args0 = couch_mrview_http:parse_qs(Req, Keys),
+    ETagFun = fun(Sig, Acc0) ->
+        couch_mrview_http:check_view_etag(Sig, Acc0, Req)
+    end,
+    Args = Args0#mrargs{preflight_fun=ETagFun},
+    {ok, Resp} = couch_httpd:etag_maybe(Req, fun() ->
+        VAcc0 = #vacc{db=Db, req=Req},
+        io:format("TRIGGERING ALL DOCS REQ WITH COUCH_MRVIEW_HTTP:VIEW_CB~n", []),
+        fabric:all_docs(Db, fun couch_mrview_http:view_cb/2, VAcc0, Args)
+    end),
+    case is_record(Resp, vacc) of
+        true -> {ok, Resp#vacc.resp};
+        _ -> {ok, Resp}
+    end.
 
 db_doc_req(#httpd{method='DELETE'}=Req, Db, DocId) ->
     % check for the existence of the doc to handle the 404 case.