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 A903C2A41 for ; Thu, 21 Apr 2011 12:09:07 +0000 (UTC) Received: (qmail 80704 invoked by uid 500); 21 Apr 2011 12:09:05 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 80655 invoked by uid 500); 21 Apr 2011 12:09:05 -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 80647 invoked by uid 99); 21 Apr 2011 12:09:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Apr 2011 12:09:05 +0000 X-ASF-Spam-Status: No, hits=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED X-Spam-Check-By: apache.org Received-SPF: unknown (nike.apache.org: error in processing during lookup of N.Breunese@vpro.nl) Received: from [145.58.30.185] (HELO out1b.mail.omroep.nl) (145.58.30.185) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Apr 2011 12:08:56 +0000 Received: from localhost (ou1bclean [10.10.30.159]) by out1b.mail.omroep.nl (Postfix MTA - NPO ICT) with ESMTP id 4779C400579 for ; Thu, 21 Apr 2011 14:08:36 +0200 (CEST) X-Virus-Scanned: NPO ICT Received: from vergiet.vpro.nl (vergiet.vpro.nl [145.58.168.40]) by out1b.mail.omroep.nl (Postfix MTA - NPO ICT) with ESMTP id 2EA4C400578 for ; Thu, 21 Apr 2011 14:08:36 +0200 (CEST) X-ASG-Debug-ID: 1303387711-008352783a201cb0001-z14J5S Received: from mail.vpro.nl (mail.vpro.nl [145.58.171.81]) by vergiet.vpro.nl with ESMTP id RoJiluBrUe18AESI for ; Thu, 21 Apr 2011 14:08:31 +0200 (CEST) X-Barracuda-Envelope-From: N.Breunese@vpro.nl X-Barracuda-Apparent-Source-IP: 145.58.171.81 Received: from VS-EX-01.intra.vpro.nl ([145.58.171.81]) by VS-EX-01.intra.vpro.nl ([145.58.171.81]) with mapi; Thu, 21 Apr 2011 14:08:31 +0200 From: Nils Breunese To: "user@couchdb.apache.org" Date: Thu, 21 Apr 2011 14:08:31 +0200 Subject: Re: Dealing with sealed docs Thread-Topic: Dealing with sealed docs X-ASG-Orig-Subj: Re: Dealing with sealed docs Thread-Index: AcwAHNTMNxpcqc4nSvSQsfzot85D5A== Message-ID: <01003516-B188-4BFC-8EA5-18E6FF3A33DA@vpro.nl> References: <6084E307-7CFB-4BAD-A12C-063272628B95@vpro.nl> <95333123-2B25-4E26-8C8A-D502C88D96B3@apache.org> <4DAEF166.3020706@gmail.com> <4DAF76EF.7020400@gmail.com> In-Reply-To: <4DAF76EF.7020400@gmail.com> Accept-Language: nl-NL Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: nl-NL Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Barracuda-Connect: mail.vpro.nl[145.58.171.81] X-Barracuda-Start-Time: 1303387711 X-Barracuda-URL: http://145.58.168.40:8000/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at vpro.nl X-Barracuda-Bayes: SPAM GLOBAL 0.9685 1.0000 3.9803 X-Barracuda-Spam-Score: 3.98 X-Barracuda-Spam-Status: No, SCORE=3.98 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.2.61499 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Virus-Checked: Checked by ClamAV on apache.org Patrick Barnes wrote: > My apologies - I have mis-remembered. No, there is no clone operator, > but some functions will return a copy rather than a reference. > > I had a view that looked like: > function(doc) { > if (doc.status=3D=3D'active' && doc.doc_type=3D=3D'group') { > doc.path.pop(); > emit(doc.path, doc.display_name); > } > } > And it (on pre-1.0.2 couchdb) failed to generate the views properly, > because doc.path.pop() was modifying the doc and the next views were > receiving that modified version. > > In my case, changing the view to this fixed it: > function(doc) { > if (doc.status=3D=3D'active' && doc.doc_type=3D=3D'group') { > path =3D doc.path.slice(0); > path.pop(); > emit(path, doc.display_name); > } > } > > So doc.path.slice(0) copies the whole doc.path array for me so that I > can modify it before emitting. No such neat method exists for objects > unfortunately, but how about: > > function(doc) { > if(doc.type =3D=3D=3D 'schedule') { > var events =3D doc.events; > if (events) { > events.forEach(function(event) { > var broadcasters =3D event.broadcasters; > if (broadcasters) { > broadcasters.forEach(function(broadcaster) { > if(broadcaster =3D=3D=3D 'VPRO') { > - event.channel =3D doc.channel; > - event.channelName =3D doc.channelName; > - emit(event.end, event); > + var _event =3D {channel:doc.channel, > channelName:doc.channelName}; > + for (var k in event) _event[k]=3Devent[k]; > + emit(event.end, _event); > } > }); > } > }); > } > } > } > > The members of _event are only references, but that should be okay > because you're not modifying those, only adding two extra attributes to > the new object created. (Not having to _copy_ every element should also > make this approach much faster than using a generic 'clone' method) > > Hope that works. :-) Thanks, I'm using this approach now and it seems to work. Nils. ------------------------------------------------------------------------ VPRO www.vpro.nl ------------------------------------------------------------------------