Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-07-06 18:11:20 +0300
committerRémy Coutable <remy@rymai.me>2017-07-06 18:11:20 +0300
commitde9eca0af65e8fd235aed8c9ea598f16562956e7 (patch)
tree4b045079c29acc0d0238d7eeb2337db5e90bf707 /lib/gitlab/performance_bar.rb
parente5a7d1da8cfda5dc3755b6a0a1ed450415f39873 (diff)
Use Rails.cache instead of Redis directly
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib/gitlab/performance_bar.rb')
-rw-r--r--lib/gitlab/performance_bar.rb29
1 files changed, 7 insertions, 22 deletions
diff --git a/lib/gitlab/performance_bar.rb b/lib/gitlab/performance_bar.rb
index 85f4371ec23..f48d0506994 100644
--- a/lib/gitlab/performance_bar.rb
+++ b/lib/gitlab/performance_bar.rb
@@ -3,7 +3,7 @@ module Gitlab
ALLOWED_USER_IDS_KEY = 'performance_bar_allowed_user_ids'.freeze
# The time (in seconds) after which a set of allowed user IDs is expired
# automatically.
- ALLOWED_USER_IDS_TIME_TO_LIVE = 10.minutes.to_i
+ ALLOWED_USER_IDS_TIME_TO_LIVE = 10.minutes
def self.enabled?(current_user = nil)
Feature.enabled?(:gitlab_performance_bar, current_user)
@@ -20,28 +20,13 @@ module Gitlab
end
def self.allowed_user_ids
- Gitlab::Redis.with do |redis|
- if redis.exists(cache_key)
- redis.smembers(cache_key).map(&:to_i)
- else
- group = Group.find_by_full_path(allowed_group_name)
- # Redis#sadd doesn't accept an empty array, but we still want to use
- # Redis to let us know that no users are allowed, so we set the
- # array to [-1] in this case.
- user_ids =
- if group
- GroupMembersFinder.new(group).execute
- .pluck(:user_id).presence || [-1]
- else
- [-1]
- end
-
- redis.multi do
- redis.sadd(cache_key, user_ids)
- redis.expire(cache_key, ALLOWED_USER_IDS_TIME_TO_LIVE)
- end
+ Rails.cache.fetch(cache_key, expires_in: ALLOWED_USER_IDS_TIME_TO_LIVE) do
+ group = Group.find_by_full_path(allowed_group_name)
- user_ids
+ if group
+ GroupMembersFinder.new(group).execute.pluck(:user_id)
+ else
+ []
end
end
end