2017-05-17 07:20:55 -04:00
|
|
|
module Gitlab
|
|
|
|
module PerformanceBar
|
2017-08-31 05:47:03 -04:00
|
|
|
extend Gitlab::CurrentSettings
|
2017-07-06 12:57:02 -04:00
|
|
|
|
2017-07-17 07:28:51 -04:00
|
|
|
ALLOWED_USER_IDS_KEY = 'performance_bar_allowed_user_ids:v2'.freeze
|
|
|
|
EXPIRY_TIME = 5.minutes
|
2017-07-04 10:15:24 -04:00
|
|
|
|
2017-07-06 20:34:51 -04:00
|
|
|
def self.enabled?(user = nil)
|
|
|
|
return false unless user && allowed_group_id
|
2017-06-21 10:59:13 -04:00
|
|
|
|
2017-07-04 10:15:24 -04:00
|
|
|
allowed_user_ids.include?(user.id)
|
2017-06-21 10:59:13 -04:00
|
|
|
end
|
|
|
|
|
2017-07-06 12:57:02 -04:00
|
|
|
def self.allowed_group_id
|
|
|
|
current_application_settings.performance_bar_allowed_group_id
|
2017-07-04 10:15:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.allowed_user_ids
|
2017-07-17 07:28:51 -04:00
|
|
|
Rails.cache.fetch(ALLOWED_USER_IDS_KEY, expires_in: EXPIRY_TIME) do
|
2017-07-06 12:57:02 -04:00
|
|
|
group = Group.find_by_id(allowed_group_id)
|
2017-06-21 10:59:13 -04:00
|
|
|
|
2017-07-06 11:11:20 -04:00
|
|
|
if group
|
|
|
|
GroupMembersFinder.new(group).execute.pluck(:user_id)
|
|
|
|
else
|
|
|
|
[]
|
2017-06-28 13:18:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-06 12:57:02 -04:00
|
|
|
def self.expire_allowed_user_ids_cache
|
|
|
|
Rails.cache.delete(ALLOWED_USER_IDS_KEY)
|
2017-05-17 07:20:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|