couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zachary Zolton <zachary.zol...@gmail.com>
Subject Ordering By Votes (Tallying in a Reduce?)
Date Tue, 21 Apr 2009 16:55:34 GMT
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