stopgap measure for #1210

This commit is contained in:
r888888888
2013-04-26 17:54:38 -07:00
parent 31464d54b5
commit e861425315
5 changed files with 49 additions and 2 deletions

View File

@@ -204,8 +204,17 @@ class User < ActiveRecord::Base
Favorite.where("user_id % 100 = #{id % 100} and user_id = #{id}").order("id desc")
end
def clean_favorite_count?
favorite_count < 0 || rand(100) < [Math.log(favorite_count, 2), 5].min
end
def clean_favorite_count!
update_column(:favorite_count, Favorite.for_user(id).count)
end
def add_favorite!(post)
Favorite.add(post, self)
clean_favorite_count! if clean_favorite_count?
end
def remove_favorite!(post)