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 -- Posted via http://www.ruby-forum.com/.
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? On 1/9/06, Ethan Schreiber <ethanschreiber@yahoo.com> wrote:> > 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060109/7ede8590/attachment.html
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? -- Posted via http://www.ruby-forum.com/.