mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:11:08 +08:00
FEATURE: if site is under extreme load show anon view
If a particular path is being hit extremely hard by logged on users, revert to anonymous cached view. This will only come into effect if 3 requests queue for longer than 2 seconds on a *single* path. This can happen if a URL is shared with the entire forum base and everyone is logged on
This commit is contained in:
@ -80,14 +80,17 @@ class RateLimiter
|
||||
PERFORM_LUA_SHA = Digest::SHA1.hexdigest(PERFORM_LUA)
|
||||
end
|
||||
|
||||
def performed!
|
||||
def performed!(raise_error: true)
|
||||
return if rate_unlimited?
|
||||
now = Time.now.to_i
|
||||
|
||||
if ((max || 0) <= 0) ||
|
||||
(eval_lua(PERFORM_LUA, PERFORM_LUA_SHA, [prefixed_key], [now, @secs, @max]) == 0)
|
||||
|
||||
raise RateLimiter::LimitExceeded.new(seconds_to_wait, @type)
|
||||
raise RateLimiter::LimitExceeded.new(seconds_to_wait, @type) if raise_error
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
rescue Redis::CommandError => e
|
||||
if e.message =~ /READONLY/
|
||||
|
Reference in New Issue
Block a user