From dev-return-22263-apmail-couchdb-dev-archive=couchdb.apache.org@couchdb.apache.org Wed May 16 13:36:15 2012 Return-Path: X-Original-To: apmail-couchdb-dev-archive@www.apache.org Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 73087C2A2 for ; Wed, 16 May 2012 13:36:15 +0000 (UTC) Received: (qmail 61060 invoked by uid 500); 16 May 2012 13:36:15 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 60957 invoked by uid 500); 16 May 2012 13:36:14 -0000 Mailing-List: contact dev-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 dev@couchdb.apache.org Received: (qmail 60949 invoked by uid 99); 16 May 2012 13:36:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 May 2012 13:36:14 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of bchesneau@gmail.com designates 209.85.217.180 as permitted sender) Received: from [209.85.217.180] (HELO mail-lb0-f180.google.com) (209.85.217.180) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 May 2012 13:36:10 +0000 Received: by lbbgh12 with SMTP id gh12so665220lbb.11 for ; Wed, 16 May 2012 06:35:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=E/T6b2itKxAYSCHanJqT8Ds/UaiZ3oIzdyTRqQesufk=; b=KWELw59tIObBdPaa5HPWwQJSFXdC1Jt5Z6sbXHP6U/N+h+m0zZYQX02FocuwKGAhUZ KTw0IRSK6b/az908LtkOwPsqEe6AnezQ3DekFMI9wuGlvRlHRqWsRBN6wMZ3toFFBn2c pv3a15m+nYsq3PtFh2BgCC6Xufmi7K0OfIzdzVS6omTxdNWsAGJrhGunZ+JY/MRtyRhC V+gXJmHfh59mbaVYZLA055b5JfqUzDhoXlc6G8n7rj4J5UMy4T29s+bKzAhTPVVYUWgi efHWR6zTQ8fQpG0/aDm/TDIksfIVe7lU/ETrN+XqmRzfdsqWTqnMA/7yqLdAeuXMYTD8 31mQ== MIME-Version: 1.0 Received: by 10.152.148.101 with SMTP id tr5mr2925038lab.36.1337175348966; Wed, 16 May 2012 06:35:48 -0700 (PDT) Received: by 10.112.28.196 with HTTP; Wed, 16 May 2012 06:35:48 -0700 (PDT) In-Reply-To: References: Date: Wed, 16 May 2012 15:35:48 +0200 Message-ID: Subject: Re: Hierarchical comments Hacker News style From: Benoit Chesneau To: dev@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Wed, May 16, 2012 at 3:19 PM, Luca Matteis wrote: > Ok. Where would it be appropriate to build such a tree? Can I do it in > a list function? > I'm using Couch directly and not interacting with it using other > languages, so I need Couch to do all the work. > > On Wed, May 16, 2012 at 3:14 PM, Dirkjan Ochtman wro= te: >> On Wed, May 16, 2012 at 2:53 PM, Luca Matteis wrote= : >>> Isn't there a better way? >> >> Since the ordering of descendants depends on the scores of ancestors >> (if you're talking about getting the whole thread in order), and you >> don't want to update descendants when ancestors get modified (scores), >> there by definition is no way to cleanly do this. I think the best way >> you can do it is to emit the [ancestor_id, score] for each comment, >> which I think would allow you to build the tree structure in a single >> loop over all documents: >> >> docs, roots =3D {}, [] >> for key, doc in documents: >> =A0 =A0if key[0] =3D=3D null: >> =A0 =A0 =A0 =A0 roots.append(doc.id) >> =A0 =A0docs[doc.id] =3D doc >> =A0 =A0if key[0]: >> =A0 =A0 =A0 =A0 docs[key[0]].children.append(doc.id) >> >> (In horrible pseudo-Python-JS.) >> >> Cheers, >> >> Dirkjan Have a look here : https://github.com/benoitc/nymphormation It exactly implement that as a couchapp. - benoit