Forum: Ruby on Rails Rating/Survey Plugin

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9706a21024e929b1f8d74f64dd2910da?d=identicon&s=25 Ethan Schreiber (etschreiber)
on 2006-01-09 08:59
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
C29d9db03853958c4de5ee6b06edd39a?d=identicon&s=25 Nicolas Buet (Guest)
on 2006-01-09 17:18
(Received via mailing list)
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 ;-)

Does this help?
9706a21024e929b1f8d74f64dd2910da?d=identicon&s=25 Ethan Schreiber (etschreiber)
on 2006-01-09 23:29
Nicolas Buet 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 ;-)
>
> 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?
This topic is locked and can not be replied to.