couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <paul.joseph.da...@gmail.com>
Subject Re: Ordering By Votes (Tallying in a Reduce?)
Date Tue, 21 Apr 2009 18:39:46 GMT
Zachary,

To be certain I'd have to see a copy of your map/reduce functions but
it sounds like you're hitting the
too-much-data-being-returned-from-reduce bug.

To do this in a CouchDB way my first thoughts would be to do something
like the following:

Two maps, one for getting messages associated with pages and then one
to accumulate votes by message_id. Your app then gets a page and its
messages via the traditional couchdb joins pattern and then your app
uses multiget on the accumulated votes view. Getting the messages
sorted by votes would then be in app logic.

HTH,
Paul Davis

On Tue, Apr 21, 2009 at 12:55 PM, Zachary Zolton
<zachary.zolton@gmail.com> wrote:
> Hi all,
>
> I'm currently working on an app where there are many "Pages"
> (identified by a page_id, of sorts), which may contain "Messages".
> Message documents having the matching page_id belong to a given Page,
> where users can cast "Vote" documents, indicating whether or not a
> user likes a Message.
>
> I would like to efficiently be able to do two things:
>
> 1) Show all Messages, for a Page, ordered descending by up Votes - down Votes
> 2) Show the top Message, for a list of Pages, given the ordering in #1
>
> I currently have a view, keyed on page_id, that reduces to an object
> containing the sorted array of Message IDs.
>
> So, for example, the following could be returned for page_id 123:
>
> { "sorted_messages": [
>        { "message_id": "XXXXXX", "up_votes": 5, "down_votes": 2 },
>        { "message_id": "YYYYYY", "up_votes": 4, "down_votes": 2 },
>        { "message_id": "ZZZZZZZ", "up_votes": 2, "down_votes": 1 }
> ] }
>
> In my informal testing, this seems to be slow to update the next time
> someone views any particular Page, or when I show a list of many
> Pages, where I post a list of event_id keys. Plus, I'm not sure that
> maintaining objects like these in the reduce is the "Couch Way".
>
> Any suggestions?
>
>
> Cheers,
>
> Zach
>

Mime
View raw message