favorites: don't regen fav count when adding favorites.

Don't randomly regen the fav count when favoriting a post. This was a
workaround for #1210 that is no longer needed.
This commit is contained in:
evazion
2017-08-02 18:25:01 -05:00
committed by r888888888
parent af42740ca9
commit 5a6cc84817
2 changed files with 0 additions and 22 deletions

View File

@@ -286,17 +286,8 @@ class User < ApplicationRecord
Favorite.where("user_id % 100 = #{id % 100} and user_id = #{id}").order("id desc")
end
def clean_favorite_count?
favorite_count < 0 || Kernel.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: post, user: self)
clean_favorite_count! if clean_favorite_count?
end
def remove_favorite!(post)

View File

@@ -38,19 +38,6 @@ class UserTest < ActiveSupport::TestCase
end
end
context "favoriting a post" do
setup do
@user.update_column(:favorite_count, 999)
@user.stubs(:clean_favorite_count?).returns(true)
@post = FactoryGirl.create(:post)
end
should "periodically clean the favorite_count" do
@user.add_favorite!(@post)
assert_equal(1, @user.favorite_count)
end
end
context "that has been invited by a mod" do
setup do
@mod = FactoryGirl.create(:moderator_user)