27Jul/081
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
end
end
[/geshi]

Januar 31st, 2010 - 13:50
Lustig, ich hätte garnicht gedacht das das *wirklich* so funktioniert. Komische Welt.