diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /lib/gitlab/application_rate_limiter.rb | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'lib/gitlab/application_rate_limiter.rb')
-rw-r--r-- | lib/gitlab/application_rate_limiter.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/gitlab/application_rate_limiter.rb b/lib/gitlab/application_rate_limiter.rb index 0c52ce8aba4..a2d79b189a3 100644 --- a/lib/gitlab/application_rate_limiter.rb +++ b/lib/gitlab/application_rate_limiter.rb @@ -65,6 +65,8 @@ module Gitlab # per user (scope)) # @param threshold [Integer] Optional threshold value to override default # one registered in `.rate_limits` + # @param interval [Integer] Optional interval value to override default + # one registered in `.rate_limits` # @param users_allowlist [Array<String>] Optional list of usernames to # exclude from the limit. This param will only be functional if Scope # includes a current user. @@ -72,7 +74,7 @@ module Gitlab # incremented but the current throttled state will be returned. # # @return [Boolean] Whether or not a request should be throttled - def throttled?(key, scope:, resource: nil, threshold: nil, users_allowlist: nil, peek: false) + def throttled?(key, scope:, resource: nil, threshold: nil, interval: nil, users_allowlist: nil, peek: false) raise InvalidKeyError unless rate_limits[key] strategy = resource.present? ? IncrementPerActionedResource.new(resource.id) : IncrementPerAction.new @@ -85,7 +87,7 @@ module Gitlab return false if threshold_value == 0 - interval_value = interval(key) + interval_value = interval || interval(key) return false if interval_value == 0 @@ -112,11 +114,12 @@ module Gitlab # @param key [Symbol] Key attribute registered in `.rate_limits` # @param scope [Array<ActiveRecord>] Array of ActiveRecord models to scope throttling to a specific request (e.g. per user per project) # @param threshold [Integer] Optional threshold value to override default one registered in `.rate_limits` + # @param interval [Integer] Optional interval value to override default one registered in `.rate_limits` # @param users_allowlist [Array<String>] Optional list of usernames to exclude from the limit. This param will only be functional if Scope includes a current user. # # @return [Boolean] Whether or not a request is currently throttled - def peek(key, scope:, threshold: nil, users_allowlist: nil) - throttled?(key, peek: true, scope: scope, threshold: threshold, users_allowlist: users_allowlist) + def peek(key, scope:, threshold: nil, interval: nil, users_allowlist: nil) + throttled?(key, peek: true, scope: scope, threshold: threshold, interval: interval, users_allowlist: users_allowlist) end # Logs request using provided logger |