From user-return-2250-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Sun Dec 21 02:12:55 2008 Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 77922 invoked from network); 21 Dec 2008 02:12:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Dec 2008 02:12:55 -0000 Received: (qmail 99971 invoked by uid 500); 21 Dec 2008 02:12:53 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 99928 invoked by uid 500); 21 Dec 2008 02:12:53 -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 99917 invoked by uid 500); 21 Dec 2008 02:12:53 -0000 Delivered-To: apmail-incubator-couchdb-user@incubator.apache.org Received: (qmail 99914 invoked by uid 99); 21 Dec 2008 02:12:53 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 Dec 2008 18:12:53 -0800 X-ASF-Spam-Status: No, hits=1.5 required=10.0 tests=SPF_PASS,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of antony.blakey@gmail.com designates 209.85.198.226 as permitted sender) Received: from [209.85.198.226] (HELO rv-out-0506.google.com) (209.85.198.226) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Dec 2008 02:12:43 +0000 Received: by rv-out-0506.google.com with SMTP id f9so2629666rvb.6 for ; Sat, 20 Dec 2008 18:12:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:cc:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:mime-version :subject:date:references:x-mailer; bh=1BAoJtk/bBsduYy35ZGpedWhGaWED/XS5Bt/CkkDuUo=; b=jbdQj0DpLLUfD0adIVkhWBFBGOX45spIQ2dMvJAcn1Ea+u9RdgHaKk9htvhTNjvOYQ CkCz7UrgJRf5NB58YQS7cMowANHRCJl/IWGzWr5anaF+gEMj3qtFhXdA7aojmVUTcqER 8md0od3mK2Y0bE3XGyQK1zxDNGzh/+dKnbpZY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=cc:message-id:from:to:in-reply-to:content-type :content-transfer-encoding:mime-version:subject:date:references :x-mailer; b=TKpA8/V7EYFgItj1/a3P0syRsZjuh+R4z/85KoNsrlXlIac9Nj442W8PEn6Wuqz9Dk OZaRcRdo2ZURBaMP9mjSyxno+rJu2Df2iB8vI563fI6ozSP/9mifkXvLfCYtUiMmHDSS CST5jjeMGXgk2O+Z3ZpaFeNo6aIVxr9Y1cRqE= Received: by 10.141.203.7 with SMTP id f7mr2434744rvq.125.1229825542179; Sat, 20 Dec 2008 18:12:22 -0800 (PST) Received: from ?192.168.0.16? (ppp121-45-41-103.lns10.adl2.internode.on.net [121.45.41.103]) by mx.google.com with ESMTPS id k2sm9568342rvb.6.2008.12.20.18.12.19 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 20 Dec 2008 18:12:21 -0800 (PST) Cc: couchdb-user@incubator.apache.org Message-Id: <27BFB81F-9AE2-419C-8911-3F26D82A7A44@gmail.com> From: Antony Blakey To: Tim Parkin In-Reply-To: <494D94AF.8040305@timparkin.co.uk> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v929.2) Subject: Re: couchdb Date: Sun, 21 Dec 2008 12:42:16 +1030 References: <494D94AF.8040305@timparkin.co.uk> X-Mailer: Apple Mail (2.929.2) X-Virus-Checked: Checked by ClamAV on apache.org Posted to couchdb-users because this might be of general interest. On 21/12/2008, at 11:28 AM, Tim Parkin wrote: > Hi Anthony, > > in short.. I'm interested in your emails about CouchDB relations and > _externals/update notifiers.. in longer .. > > I'm following CouchDB at the moment and an app I'm building works with > 'related' data. My methodology is basically a form of view cacheing.. > > i.e. I have a photogrpahic holiday app.. > > I have a db where I have a few different documents, some marked as > 'tours', some marked as 'leaders'. > > When I get a tour out, I'd like some information abou the tour leader. > > I've created a view which gives me that information (e.g. Gets first > name and last name) > > I've then tied in the update process so thatwhen the leaders first > name > or last name changes, I cache this view on the tour. > > This allows me to get a bunch of data I need for tours in one go > without > getting the tour leader out (OK this is a fairly trivial example but > some tours have three assistants and other 'remote' attributes). > > I'd really like to have this trigger process happen on the server but > haven't worked out how to do it.. I've read a lot of your posts and > you > seem to have approached problem(s) like this and I'd be interested in > your recommmendation. > > At the moment I'm looking at triggering an _external from an update > notification (rather like your post > http://markmail.org/message/wikw4vggx4uew5kz?q=couchdb+_external&page=1&refer=uwkon7i337iq6yxf) I don't recommend having the notification trigger anything but setting a dirty-flag. I've tried to get a response from the gatekeepers about the intended synchronization contract between update notifications and _external request, to no avail. IMO without that being synchronous, it's not that useful. I do it all in the _external, which is good because it then has the same lazy-update characteristics as a view. A test handler follows. This is in ruby just because I'm doing some ruby at the moment. I use SQLite as the index database because it's in-process and really easy. The result I return from the _external call is not structured like a view result in this code (it's just test code) The 'src' field in the 'links' table happens to be the doc_id, so I can remove entries when I notice a deletion. Without that, I would have to include the doc_id separately in the table so that I could handle the deletion of documents. I cheat for this system and use a domain-value key (the email address of the user). I do this because I use a single-writer peer to get a cheap uniqueness constraint. For my app, read-only replication is sufficient USP. I'm not accepting any parameters in my _external request - I return the entire db (it's just test code). If you look at Paul Davis's recent post about _external you can see that the query parameters to the _external request are supplied in the per-request json, so dealing with that is trivial. This code was written to use my own _external erlang code - I think the db_name and update_seq fields are nested in some other structure in the newly-official _external handler, and you'll need a HEAD version of couchdb to make this work in any case, because you need the update_seq. Anyway, here is some code --------------------------------------------------------------------- require 'rubygems' require 'json' require 'couchrest' require 'cgi' require 'sqlite3' # Need a command line parameter in the .ini rather than hardcoding this db = SQLite3::Database.new("/usr/local/var/lib/couchdb/bims-users- index.db") sql = < 200, "json" => rows } STDOUT.puts result.to_json STDOUT.flush end --------------------------------------------------------------------- Antony Blakey ------------- CTO, Linkuistics Pty Ltd Ph: 0438 840 787 It is no measure of health to be well adjusted to a profoundly sick society. -- Jiddu Krishnamurti