Rating/Survey Plugin


#1

I would like include the ability for people to rate posts on my site
from 1 to 5. I would like to then display the average rating for each
post. To compute the average each time is obviously database and cpu
intensive. I have been thinking about the best solution. I could
certainly use a cache and expire it every x minutes. However, I don’t
want to reinvent the wheel. Is there already a ROR plugin solution out
there that I don’t know about? If not, does anyone have any good links
on this subject?

Thanks for all of your time and effort on this great project.

Ethan Schreiber


#2

You probably should store the average (A) and number of votes (N) for
each
post. Then, to display the rating of a post, you query for A in the
database. When a new rating is submitted, you compute A and you
increment N.

Note: of course, A must be stored in float (or whatever) and rounded for
display :wink:

Does this help?


#3

Nicolas B. wrote:

You probably should store the average (A) and number of votes (N) for
each
post. Then, to display the rating of a post, you query for A in the
database. When a new rating is submitted, you compute A and you
increment N.

Note: of course, A must be stored in float (or whatever) and rounded for
display :wink:

Does this help?

Thank you for your response.

Yes that is one solution that would work. However, then I would be
keeping track of individual votes as well as the total. (I need the
individual votes as well.) It seems redundant. On top of that, I need
to worry about the transaction of modifying the average column which can
run into multi-threading problems. I was looking into memory cache
solutions where i can compute the average and store it in a cache and
perhaps invalidate the cache ever 10 or 15 minutes. This lagtime would
be acceptable.

Is memcached the cache solution i should be using with ROR?