rails, acts_as_rateable, will_paginate and efficient sorting

Forget what I said here, it’s really inefficient… I just stumbled upon (or actually really searched for) a article, which describes an easy way to cache the rating and make searches as performant as it was before we put the rating into an extra table.

Only thing I had to add was a method to regenerate the cache for all the old quotes, which don’t have the cached rating yet. So, check out the howto and add the following method to your rated model:

[geshi lang=ruby]
def self.update_rating_cache
self.find(:all).each do |quote|
quote.update_attribute :rating_cache, quote.rating

What do you think of this post?
  • Awesome (0)
  • Interesting (0)
  • Useful (0)
  • Boring (0)
  • Sucks (0)

1 Antwort auf „rails, acts_as_rateable, will_paginate and efficient sorting“

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.