incubator-couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirkjan Ochtman <dirk...@ochtman.nl>
Subject Re: Hierarchical comments Hacker News style
Date Wed, 16 May 2012 13:14:08 GMT
On Wed, May 16, 2012 at 2:53 PM, Luca Matteis <lmatteis@gmail.com> 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 = {}, []
for key, doc in documents:
    if key[0] == null:
         roots.append(doc.id)
    docs[doc.id] = doc
    if key[0]:
         docs[key[0]].children.append(doc.id)

(In horrible pseudo-Python-JS.)

Cheers,

Dirkjan

Mime
View raw message