diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /lib/gitlab/application_rate_limiter.rb | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'lib/gitlab/application_rate_limiter.rb')
-rw-r--r-- | lib/gitlab/application_rate_limiter.rb | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/gitlab/application_rate_limiter.rb b/lib/gitlab/application_rate_limiter.rb index f91a56a0cd2..7c37f67b766 100644 --- a/lib/gitlab/application_rate_limiter.rb +++ b/lib/gitlab/application_rate_limiter.rb @@ -11,6 +11,23 @@ module Gitlab # redirect_to(edit_project_path(@project), status: :too_many_requests) # end class ApplicationRateLimiter + def initialize(key, **options) + @key = key + @options = options + end + + def throttled? + self.class.throttled?(key, **options) + end + + def threshold_value + options[:threshold] || self.class.threshold(key) + end + + def interval_value + self.class.interval(key) + end + class << self # Application rate limits # @@ -73,7 +90,7 @@ module Gitlab value = 0 interval_value = interval || interval(key) - Gitlab::Redis::Cache.with do |redis| + ::Gitlab::Redis::RateLimiting.with do |redis| cache_key = action_key(key, scope) value = redis.incr(cache_key) redis.expire(cache_key, interval_value) if value == 1 @@ -154,5 +171,9 @@ module Gitlab scoped_user.username.downcase.in?(options[:users_allowlist]) end end + + private + + attr_reader :key, :options end end |