BigW Consortium Gitlab

performance_bar.rb 820 Bytes
Newer Older
1 2
module Gitlab
  module PerformanceBar
3
    extend Gitlab::CurrentSettings
4

5 6
    ALLOWED_USER_IDS_KEY = 'performance_bar_allowed_user_ids:v2'.freeze
    EXPIRY_TIME = 5.minutes
7

8 9
    def self.enabled?(user = nil)
      return false unless user && allowed_group_id
10

11
      allowed_user_ids.include?(user.id)
12 13
    end

14 15
    def self.allowed_group_id
      current_application_settings.performance_bar_allowed_group_id
16 17 18
    end

    def self.allowed_user_ids
19
      Rails.cache.fetch(ALLOWED_USER_IDS_KEY, expires_in: EXPIRY_TIME) do
20
        group = Group.find_by_id(allowed_group_id)
21

22 23 24 25
        if group
          GroupMembersFinder.new(group).execute.pluck(:user_id)
        else
          []
26 27 28 29
        end
      end
    end

30 31
    def self.expire_allowed_user_ids_cache
      Rails.cache.delete(ALLOWED_USER_IDS_KEY)
32 33 34
    end
  end
end