FEATURE: scale up likes per day as users increase trust level
tl2 = 1.5 times the likes tl3 = 2 times the likes tl4 = 3 times the likes configurable via tl[234]_additional_likes_per_day_multiplier site setting
This commit is contained in:
parent
9cb928e893
commit
a5b25ad2af
|
@ -320,7 +320,16 @@ class PostAction < ActiveRecord::Base
|
||||||
|
|
||||||
%w(like flag bookmark).each do |type|
|
%w(like flag bookmark).each do |type|
|
||||||
if send("is_#{type}?")
|
if send("is_#{type}?")
|
||||||
@rate_limiter = RateLimiter.new(user, "create_#{type}", SiteSetting.send("max_#{type}s_per_day"), 1.day.to_i)
|
limit = SiteSetting.send("max_#{type}s_per_day")
|
||||||
|
|
||||||
|
if is_like? && user && user.trust_level >= 2
|
||||||
|
multiplier = SiteSetting.send("tl#{user.trust_level}_additional_likes_per_day_multiplier").to_f
|
||||||
|
multiplier = 1.0 if multiplier < 1.0
|
||||||
|
|
||||||
|
limit = (limit * multiplier ).to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
@rate_limiter = RateLimiter.new(user, "create_#{type}",limit, 1.day.to_i)
|
||||||
return @rate_limiter
|
return @rate_limiter
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -808,6 +808,10 @@ en:
|
||||||
max_topics_in_first_day: "The maximum number of topics a user is allowed to create in their first day on the site"
|
max_topics_in_first_day: "The maximum number of topics a user is allowed to create in their first day on the site"
|
||||||
max_replies_in_first_day: "The maximum number of replies a user is allowed to create in their first day on the site"
|
max_replies_in_first_day: "The maximum number of replies a user is allowed to create in their first day on the site"
|
||||||
|
|
||||||
|
tl2_additional_likes_per_day_multiplier: "Increase limit of likes per day for tl2 (member) by multiplying with this number"
|
||||||
|
tl3_additional_likes_per_day_multiplier: "Increase limit of likes per day for tl3 (regular) by multiplying with this number"
|
||||||
|
tl4_additional_likes_per_day_multiplier: "Increase limit of likes per day for tl4 (leader) by multiplying with this number"
|
||||||
|
|
||||||
num_flags_to_block_new_user: "If a new user's posts get this many spam flags from num_users_to_block_new_user different users, hide all their posts and prevent future posting. 0 to disable."
|
num_flags_to_block_new_user: "If a new user's posts get this many spam flags from num_users_to_block_new_user different users, hide all their posts and prevent future posting. 0 to disable."
|
||||||
num_users_to_block_new_user: "If a new user's posts get num_flags_to_block_new_user spam flags from this many different users, hide all their posts and prevent future posting. 0 to disable."
|
num_users_to_block_new_user: "If a new user's posts get num_flags_to_block_new_user spam flags from this many different users, hide all their posts and prevent future posting. 0 to disable."
|
||||||
notify_mods_when_user_blocked: "If a user is automatically blocked, send a message to all moderators."
|
notify_mods_when_user_blocked: "If a user is automatically blocked, send a message to all moderators."
|
||||||
|
|
|
@ -675,6 +675,9 @@ rate_limits:
|
||||||
max_invites_per_day: 10
|
max_invites_per_day: 10
|
||||||
max_topics_in_first_day: 5
|
max_topics_in_first_day: 5
|
||||||
max_replies_in_first_day: 10
|
max_replies_in_first_day: 10
|
||||||
|
tl2_additional_likes_per_day_multiplier: 1.5
|
||||||
|
tl3_additional_likes_per_day_multiplier: 2
|
||||||
|
tl4_additional_likes_per_day_multiplier: 3
|
||||||
|
|
||||||
developer:
|
developer:
|
||||||
force_hostname:
|
force_hostname:
|
||||||
|
|
|
@ -4,6 +4,8 @@ require_dependency 'rate_limiter/on_create_record'
|
||||||
# A redis backed rate limiter.
|
# A redis backed rate limiter.
|
||||||
class RateLimiter
|
class RateLimiter
|
||||||
|
|
||||||
|
attr_reader :max, :secs, :user, :key
|
||||||
|
|
||||||
def self.key_prefix
|
def self.key_prefix
|
||||||
"l-rate-limit:"
|
"l-rate-limit:"
|
||||||
end
|
end
|
||||||
|
|
|
@ -506,6 +506,33 @@ describe PostAction do
|
||||||
topic.reload
|
topic.reload
|
||||||
expect(topic.posts.count).to eq(1)
|
expect(topic.posts.count).to eq(1)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "rate limiting" do
|
||||||
|
|
||||||
|
def limiter(tl)
|
||||||
|
user = Fabricate.build(:user)
|
||||||
|
user.trust_level = tl
|
||||||
|
action = PostAction.new(user: user, post_action_type_id: PostActionType.types[:like])
|
||||||
|
action.post_action_rate_limiter
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should scale up like limits depending on liker" do
|
||||||
|
expect(limiter(0).max).to eq SiteSetting.max_likes_per_day
|
||||||
|
expect(limiter(1).max).to eq SiteSetting.max_likes_per_day
|
||||||
|
expect(limiter(2).max).to eq (SiteSetting.max_likes_per_day * SiteSetting.tl2_additional_likes_per_day_multiplier).to_i
|
||||||
|
expect(limiter(3).max).to eq (SiteSetting.max_likes_per_day * SiteSetting.tl3_additional_likes_per_day_multiplier).to_i
|
||||||
|
expect(limiter(4).max).to eq (SiteSetting.max_likes_per_day * SiteSetting.tl4_additional_likes_per_day_multiplier).to_i
|
||||||
|
|
||||||
|
SiteSetting.tl2_additional_likes_per_day_multiplier = -1
|
||||||
|
expect(limiter(2).max).to eq SiteSetting.max_likes_per_day
|
||||||
|
|
||||||
|
SiteSetting.tl2_additional_likes_per_day_multiplier = 0.8
|
||||||
|
expect(limiter(2).max).to eq SiteSetting.max_likes_per_day
|
||||||
|
|
||||||
|
SiteSetting.tl2_additional_likes_per_day_multiplier = "bob"
|
||||||
|
expect(limiter(2).max).to eq SiteSetting.max_likes_per_day
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue