couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirkjan Ochtman <>
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 <> 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:
    docs[] = doc
    if key[0]:

(In horrible pseudo-Python-JS.)



View raw message