stopgap measure for #1210
This commit is contained in:
@@ -526,12 +526,25 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
module FavoriteMethods
|
||||
def clean_fav_string?
|
||||
rand(100) < [Math.log(fav_string.size, 2), 5].min
|
||||
end
|
||||
|
||||
def clean_fav_string!
|
||||
array = fav_string.scan(/\S+/).uniq
|
||||
self.fav_string = array.join(" ")
|
||||
self.fav_count = array.size
|
||||
update_column(:fav_string, fav_string)
|
||||
update_column(:fav_count, fav_count)
|
||||
end
|
||||
|
||||
def favorited_by?(user_id)
|
||||
fav_string =~ /(?:\A| )fav:#{user_id}(?:\Z| )/
|
||||
end
|
||||
|
||||
def append_user_to_fav_string(user_id)
|
||||
update_column(:fav_string, (fav_string + " fav:#{user_id}").strip)
|
||||
clean_fav_string! if clean_fav_string?
|
||||
end
|
||||
|
||||
def add_favorite!(user)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user