Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E728C1069F for ; Sat, 8 Feb 2014 18:32:19 +0000 (UTC) Received: (qmail 12891 invoked by uid 500); 8 Feb 2014 18:32:18 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 12808 invoked by uid 500); 8 Feb 2014 18:32:18 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 12792 invoked by uid 99); 8 Feb 2014 18:32:17 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 08 Feb 2014 18:32:17 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id B7BE1920853; Sat, 8 Feb 2014 18:32:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chewbranca@apache.org To: commits@couchdb.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: chttpd commit: updated refs/heads/1993-bigcouch-couch-mrview to b2344bc Date: Sat, 8 Feb 2014 18:32:17 +0000 (UTC) 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 Authored: Sat Feb 8 10:28:51 2014 -0800 Committer: Russell Branca 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.