Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E663243D3 for ; Mon, 23 May 2011 06:44:53 +0000 (UTC) Received: (qmail 10600 invoked by uid 500); 23 May 2011 06:44:52 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 10577 invoked by uid 500); 23 May 2011 06:44:51 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 10569 invoked by uid 99); 23 May 2011 06:44:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 May 2011 06:44:50 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of bchesneau@gmail.com designates 209.85.214.52 as permitted sender) Received: from [209.85.214.52] (HELO mail-bw0-f52.google.com) (209.85.214.52) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 May 2011 06:44:45 +0000 Received: by bwj24 with SMTP id 24so6681630bwj.11 for ; Sun, 22 May 2011 23:44:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=gpKIp1D4rTNebS1YcH1LBoI3lITeJ6rD6pBQwTj2xrM=; b=YWAouNAosjxmV4FGDMslD1tyYcnUzThOE9ylWq4+aU02Rt6jzDOaSYP7xfKZZqEXc6 FgoZ2hRD7vqtX5DiKwTn4whmZ0dgnTwV6n10MP1jW4InP15GSDoZEavnnfQhCJg4kSuH bGQp8Okaw/ZZoihdlGABfS6D0jJ4ahisBFRlU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=eaFcJN0LdvVbe9qvmwcrfPg1/VJ0do/MRcDr9Q3DZWDBTiqPgoV9Ahpcu9AyT8VDBm 3br46cWMU55mu8F4IT1GFhYJWuSILsLlIMcRwAollBeP8W12ZHOxa6v+z2DMIZuXXWlO I5E000BR5HtDXrZLvUj9tYx/4eyIc92m0VTuE= MIME-Version: 1.0 Received: by 10.204.116.134 with SMTP id m6mr1840056bkq.7.1306133063873; Sun, 22 May 2011 23:44:23 -0700 (PDT) Received: by 10.204.14.143 with HTTP; Sun, 22 May 2011 23:44:23 -0700 (PDT) In-Reply-To: References: Date: Mon, 23 May 2011 08:44:23 +0200 Message-ID: Subject: Re: DB that mirrors a view From: Benoit Chesneau To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Mon, May 23, 2011 at 7:55 AM, afters wrote: > Jason, > > Thanks for the detailed answer! I've actually written code along the same > lines as yours (only with eval instead of 'new Function' - thanks for the > tip). > > I'm actually interested in the reduce results, rather than the map result= s. > It's still possible to deduce the affected reduce-keys for each change, j= ust > by using the map function: just clip the emitted map key according to the > desired group_level. Alas, it's not possible to deduce the query results = - > as reduce depends also on previous changes. > > If only I could prevent the view from being updated for a little while, I > could read the changes feed till I'm in line with the view's seqnum... > > Benoit, if you're reading this I'd love to hear more about your fork. > > =A0a. > > On 23 May 2011 04:25, Jason Smith wrote: > >> I think Benoit has a fork of CouchDB to do this. Also I believe this >> feature (a _changes filter that only shows docs that change a view) is >> possibly coming in the future. >> >> As a side-note, view queries support an ?update_seq=3Dtrue parameter, >> which will tell you the seqnum of the database which that view >> represents. >> >> Anyway, probably the best bang-for-buck with NodeJS is simply to >> download the design document and run the map() functions yourself. >> They are purely functional, and they have no (or perhaps well-known) >> side-effects. >> >> The basic idea is: >> >> 1. Fetch the design document as JSON >> 2. Extract the .views.whatever.map value as a string >> 3. Build a wrapper map() function that has a custom emit() >> 4. Run it for every _changes update >> >> Below is my basic idea. I think I've seen it elsewhere, perhaps in >> Benoit's fork. But this is with Node. It could use some optimization >> too (don't re-define map() every function call). >> >> var ddoc =3D get_ddoc(); >> var couch_map =3D ddoc.views.someview.map; >> >> var changed_keys =3D []; >> function emit(key, val) { >> =A0console.log("Emit! " + JSON.stringify(key)); >> =A0changed_keys.push(key); >> } >> >> var map =3D new Function("doc, emit", "var couch_map =3D " + couch_map + >> "; couch_map(doc);); >> >> changes.forEach(function(change) { >> =A0map(change.doc, emit); >> }) >> >> console.log("These keys were emitted: " + JSON.stringify(changed_keys)); >> >> > Hi guys, >> > >> > I'm giving a serious look into building a db that mirrors the contents= of >> a >> > view (for running map on the results of map-reduce). >> > >> > The hurdle that I'm facing is tracking changes in the view: >> > It's possible to listen to the db's changes feed and deduce which >> view-keys >> > should be updated for a particular seqnum, then query the view with th= ese >> > keys. Unfortunately, the view would only return the latest results, th= at >> may >> > easily incorporate changes from later seqnums, thus making my mirrorin= g >> db >> > inconsistent with the view. >> > >> > Any thoughts? Has anyone else meddled with turning a view to a db? >> > It would be useful if I could somehow freeze the update of the view (I >> guess >> > I could do it by replicating its db only to a certain point, but that >> would >> > mean a whole other db) >> > >> > Thanks, >> > =A0a. >> > >> >> >> >> -- >> Iris Couch >> > Hi, Indeed, in trunk and 1.1 you can pass a _view filter to change then a view param view=3Ddname/vname that allows you to get all changes using the map function and then know if your view have been updated. Maybe that can help. - beno=EEt