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 222C998B9 for ; Wed, 16 May 2012 13:19:48 +0000 (UTC) Received: (qmail 2387 invoked by uid 500); 16 May 2012 13:19:47 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 2354 invoked by uid 500); 16 May 2012 13:19:47 -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 2345 invoked by uid 99); 16 May 2012 13:19:47 -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:19:47 +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 lmatteis@gmail.com designates 209.85.215.180 as permitted sender) Received: from [209.85.215.180] (HELO mail-ey0-f180.google.com) (209.85.215.180) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 May 2012 13:19:42 +0000 Received: by eaai12 with SMTP id i12so203858eaa.11 for ; Wed, 16 May 2012 06:19:21 -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=X4x1jWJsQcArI9+HIZ1jq/Te46fxJwykrMoQpVY0N8k=; b=crSREloHB78aMLk3beWvnBgG6pqKi7f2SachlYaEqWY6/WbfJqjY9t+MpluMTpHJos lAT44tK0c6D8McTx86Ncu/2X7e7p5d/iQ4Wa0DkJ8ZhbmR3xw7qwRz8UCuna7SVTqMpY h4ObdUf2wpNuPiY3OGlIXR1DPMFlZd5YtjRkimtZ77iQbcgyg37ORuBBEZZLtQw+HpYT Nujfa5u4QotUXRtna9AtRy90XQJww+gUnJGrSrZuzJ/O6UuFLEZX96kUqXvv6a12Dv9V zyhxeBLzhQl4a6Be7HL8P543jfpPY31MSUfs7ahX+7uaA9EqH+rSYMAimIEQ0KAsojdd d6vw== MIME-Version: 1.0 Received: by 10.213.108.195 with SMTP id g3mr1442902ebp.11.1337174361349; Wed, 16 May 2012 06:19:21 -0700 (PDT) Received: by 10.14.188.8 with HTTP; Wed, 16 May 2012 06:19:21 -0700 (PDT) In-Reply-To: References: Date: Wed, 16 May 2012 15:19:21 +0200 Message-ID: Subject: Re: Hierarchical comments Hacker News style From: Luca Matteis 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 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 wrote= : > 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