Return-Path: Delivered-To: apmail-incubator-couchdb-dev-archive@locus.apache.org Received: (qmail 74692 invoked from network); 7 Aug 2008 03:58:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Aug 2008 03:58:27 -0000 Received: (qmail 22183 invoked by uid 500); 7 Aug 2008 03:58:26 -0000 Delivered-To: apmail-incubator-couchdb-dev-archive@incubator.apache.org Received: (qmail 22149 invoked by uid 500); 7 Aug 2008 03:58:26 -0000 Mailing-List: contact couchdb-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-dev@incubator.apache.org Delivered-To: mailing list couchdb-dev@incubator.apache.org Received: (qmail 22138 invoked by uid 99); 7 Aug 2008 03:58:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Aug 2008 20:58:26 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jchris@gmail.com designates 74.125.46.158 as permitted sender) Received: from [74.125.46.158] (HELO yw-out-1718.google.com) (74.125.46.158) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Aug 2008 03:57:28 +0000 Received: by yw-out-1718.google.com with SMTP id 5so166129ywr.0 for ; Wed, 06 Aug 2008 20:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=RaKqxKaOQqz4S12O22VYQQLrXaVpfmntGDkcJ3DfDA0=; b=vpzm1SXhBewhzuGET03qJLRJYaWWyrkcMDbioQpOIlCMdCqGCblqnT6jM42gRmJQgo xp2i1tyvs/q4VtAZyGUvbzZ0M0uet2nPBzSHuXBg+LUxofVMa7ATh9slW3YAAYKlhrWR HMsrLJBUsAVBI1FzQduMuPG04ALUAas/6+GPo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=Hih1wGufZJWhul2U4NSEKh7m3zTRIcDVl1cDzw200wVcUv9VZobE25Fme+hJyZUTIk Qa7O5NU8rrnbq4jpl2zc8lprlXK0XpidQuo1nHmQ0nUcecDKLLAWUMK2fg4t9xzog6ds vcbOHeEwvoUKY/a+NkW2F1XOf9+RWPfd7VcoQ= Received: by 10.150.181.7 with SMTP id d7mr4484396ybf.249.1218081475418; Wed, 06 Aug 2008 20:57:55 -0700 (PDT) Received: by 10.151.44.19 with HTTP; Wed, 6 Aug 2008 20:57:55 -0700 (PDT) Message-ID: Date: Wed, 6 Aug 2008 20:57:55 -0700 From: "Chris Anderson" Sender: jchris@gmail.com To: couchdb-dev@incubator.apache.org Subject: Re: [PATCH] Views: Multiple keys In-Reply-To: <20080723053624.GA8963@pib-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20080723053624.GA8963@pib-laptop> X-Google-Sender-Auth: 5c8f16fd6b04f051 X-Virus-Checked: Checked by ClamAV on apache.org Thanks for the patch Paul. I updated it against current trunk and added some unit tests to it. I took the opportunity to do some refactoring and create a output_map_view function. It's working well for design docs but for some reason I can't get it to behave correctly with _temp_views. The behavior is documented in the attached unit tests, but the gist of it is that POSTs to /mydb/_view/design/view with a body like: {"keys":[array of keys]} return just the view rows that match the keys. There is still work to be done to test the interactions with other request params. I started down the path of getting reduce functions to work with keys as well, but I think that will require getting deep into couch_btree.erl The patch is here: http://friendpaste.com/7Va7jgWK If anyone can apply it and try to figure out the temp-view stuff, that'd be super helpful. Otherwise maybe sleep and a fresh look will let me finish it. Chris On Tue, Jul 22, 2008 at 10:36 PM, Paul Bonser wrote: > After exploring the source code a bit and abandoning a few other ways of achieving this, I've managed to get multi-key requests working. The only way to make it more efficient would require some digging into the couch_btree folding code, I think. > > You use it by POSTing a JSON array of keys to a view url. Any passed-in values for start_key and end_key are ignored. > > I haven't written any unittests for this yet, but I wanted to see what everyone else thinks of this and ask if there's any obvious better way to accomplish the same goal. > > This patch is against the latest in SVN as of now. Any comments or suggestions for this are very much welcome. > > > Signed-off-by: Paul Bonser > -- > > diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl > index af8d9b4..c813a4c 100644 > --- a/src/couchdb/couch_httpd.erl > +++ b/src/couchdb/couch_httpd.erl > @@ -363,6 +363,37 @@ handle_db_request(Req, 'GET', {DbName, _Db, ["_view", DocId, ViewName]}) -> > end > end; > > +% Multi-key request, with a JSON array of keys as the POST body > +handle_db_request(Req, 'POST', {DbName, _Db, ["_view", DocId, ViewName]}) -> > + #view_query_args{ > + count = Count, > + skip = SkipCount, > + direction = Dir, > + start_docid = StartDocId > + } = QueryArgs = parse_view_query(Req), > + > + case Req:get_primary_header_value("content-type") of > + undefined -> ok; > + "application/json" -> ok; > + Else -> throw({incorrect_mime_type, Else}) > + end, > + JsonKeys = tuple_to_list(cjson:decode(Req:recv_body())), > + > + {ok, View} = couch_view:get_map_view({DbName, "_design/" ++ DocId, ViewName}), > + {ok, RowCount} = couch_view:get_row_count(View), > + FoldAccInit = {Count, SkipCount, undefined, []}, > + FoldResult = lists:foldl(fun(Key, {ok, FoldAcc}) -> > + Start = {Key, StartDocId}, > + FoldlFun = make_view_fold_fun(Req, QueryArgs#view_query_args { > + start_key = Key, > + end_key = Key > + }, > + RowCount, fun couch_view:reduce_to_count/1), > + couch_view:fold(View, Start, Dir, FoldlFun, FoldAcc) > + end, {ok, FoldAccInit}, JsonKeys), > + finish_view_fold(Req, RowCount, FoldResult); > + > + > handle_db_request(_Req, _Method, {_DbName, _Db, ["_view", _DocId, _ViewName]}) -> > throw({method_not_allowed, "GET,HEAD"}); > > -- Chris Anderson http://jchris.mfdz.com