2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-15 11:46:39 -04:00
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module RequestProfiler
|
2019-08-31 15:25:25 -04:00
|
|
|
PROFILES_DIR = "#{Gitlab.config.shared.path}/tmp/requests_profiles"
|
2016-07-15 11:46:39 -04:00
|
|
|
|
2019-07-23 05:30:00 -04:00
|
|
|
def all
|
|
|
|
Dir["#{PROFILES_DIR}/*.{html,txt}"].map do |path|
|
|
|
|
Profile.new(File.basename(path))
|
|
|
|
end.select(&:valid?)
|
|
|
|
end
|
2020-09-03 17:08:18 -04:00
|
|
|
module_function :all # rubocop: disable Style/AccessModifierDeclarations
|
2019-07-23 05:30:00 -04:00
|
|
|
|
|
|
|
def find(name)
|
|
|
|
file_path = File.join(PROFILES_DIR, name)
|
|
|
|
return unless File.exist?(file_path)
|
|
|
|
|
|
|
|
Profile.new(name)
|
|
|
|
end
|
2020-09-03 17:08:18 -04:00
|
|
|
module_function :find # rubocop: disable Style/AccessModifierDeclarations
|
2019-07-23 05:30:00 -04:00
|
|
|
|
2016-07-15 11:46:39 -04:00
|
|
|
def profile_token
|
|
|
|
Rails.cache.fetch('profile-token') do
|
|
|
|
Devise.friendly_token
|
|
|
|
end
|
|
|
|
end
|
2020-09-03 17:08:18 -04:00
|
|
|
module_function :profile_token # rubocop: disable Style/AccessModifierDeclarations
|
2016-07-15 11:46:39 -04:00
|
|
|
|
|
|
|
def remove_all_profiles
|
|
|
|
FileUtils.rm_rf(PROFILES_DIR)
|
|
|
|
end
|
2020-09-03 17:08:18 -04:00
|
|
|
module_function :remove_all_profiles # rubocop: disable Style/AccessModifierDeclarations
|
2016-07-15 11:46:39 -04:00
|
|
|
end
|
|
|
|
end
|