Skip to content

Instantly share code, notes, and snippets.

@mgroebner
Created March 7, 2012 20:04
Show Gist options
  • Save mgroebner/1995665 to your computer and use it in GitHub Desktop.
Save mgroebner/1995665 to your computer and use it in GitHub Desktop.
ertl bullshit
def recalculate_score
reload
user_ids = users.collect{|u| u.id }
self.score_cache = 0
Category.all(:conditions => {:calculated => true}).each do |c|
self.score_cache += category.category_scores.all(:conditions => ["user_id IN (?)", user_ids], :order => "score_cache DESC", :limit => 3).sum(&:score_cache)
end
save(false)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment