Would storing each vote as a separate document be completely inappropriate?
On Wed, May 16, 2012 at 6:59 PM, Sean Copenhaver <[email protected]> wrote: > Well my idea is that there is a separate document that only keeps track of > the comments by hierarchy, point, and potentially order (once you have the > points any code should easily be able to get the ordering) for a single > post. That document wouldn't containt the document contents, just the ids. > So when adding a comment you'll need to associate and score it with the > post by adding it to this comment tracking document. If _changes is fast > enough that would be easy to do but also just making two requests to > CouchDB would be fairly easy. Especially if the update handler took care of > adding an entry for a new comment. > > So there would be a post document, and a document for each comment, then a > comment tracker document for each post. I think the comment tracker > document would remain fairly small even with a lot of comments since it's > only tracking very little information. > > The disadvantage is of course having to keep up with that comment tracker > document. Again an update handler could handle a lot of that but each +/- 1 > or new comment would require a call to it. > > I hope that's clear. > > On Wed, May 16, 2012 at 12:25 PM, Luca Matteis <[email protected]> wrote: > >> Sean, >> interesting. What would be the drawbacks of this other than the >> conflict issue? How would I order the comments by score - would my >> view need to do the logic? Also, what if there's *many* comments to a >> post. How much can a single document handle? >> >> Luca >> >> On Wed, May 16, 2012 at 5:32 PM, Sean Copenhaver >> <[email protected]> wrote: >> > Is it not possible to maintain the scores and ordering in a document by >> > itself? Something like >> > >> > { >> > _id: <whatever> >> > post: <post id> >> > comments: { >> > <top level comment id>: { score: ##, children: <comments of >> > similar structure> }, >> > <another top level comment id> : <etc> >> > } >> > } >> > >> > A view could easily allow one call to CouchDB retrieve the original post >> > and this comment scoring doc. Then you can load whatever level of >> comments >> > you need to and know the ordering and hierarchy. >> > >> > Score changes on a comment though you would need to keep updating this >> > document which can lead to conflicts. An update handler to increment the >> > score and reorder the comments will help with that and if a conflict >> causes >> > the update handler to error back to the client you just submit the same >> one >> > again. >> > >> > I have not implemented this solution myself, but throwing out ideas. I'm >> > certainly curious what others think is the best way. >> > >> > On Wed, May 16, 2012 at 9:33 AM, Dirkjan Ochtman <[email protected]> >> wrote: >> > >> >> On Wed, May 16, 2012 at 3:19 PM, Luca Matteis <[email protected]> >> 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. >> >> >> >> Should be possible to do it in the list function, but I haven't worked >> >> with list functions before. >> >> >> >> Also note that this topic is solidly off-topic for dev@, and should >> >> actually be discussed on user@. >> >> >> >> Cheers, >> >> >> >> Dirkjan >> >> >> > >> > >> > >> > -- >> > “The limits of language are the limits of one's world. “ - Ludwig von >> > Wittgenstein >> > >> > "Water is fluid, soft and yielding. But water will wear away rock, which >> is >> > rigid and cannot yield. As a rule, whatever is fluid, soft and yielding >> > will overcome whatever is rigid and hard. This is another paradox: what >> is >> > soft is strong." - Lao-Tzu >> > > > > -- > “The limits of language are the limits of one's world. “ - Ludwig von > Wittgenstein > > "Water is fluid, soft and yielding. But water will wear away rock, which is > rigid and cannot yield. As a rule, whatever is fluid, soft and yielding > will overcome whatever is rigid and hard. This is another paradox: what is > soft is strong." - Lao-Tzu
