2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Peek
|
|
|
|
module Views
|
|
|
|
class ActiveRecord < DetailedView
|
2019-12-04 20:38:33 +05:30
|
|
|
DEFAULT_THRESHOLDS = {
|
|
|
|
calls: 100,
|
|
|
|
duration: 3000,
|
|
|
|
individual_call: 1000
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
THRESHOLDS = {
|
|
|
|
production: {
|
|
|
|
calls: 100,
|
|
|
|
duration: 15000,
|
|
|
|
individual_call: 5000
|
|
|
|
}
|
|
|
|
}.freeze
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def results
|
|
|
|
super.merge(calls: detailed_calls)
|
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
def self.thresholds
|
|
|
|
@thresholds ||= THRESHOLDS.fetch(Rails.env.to_sym, DEFAULT_THRESHOLDS)
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
private
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def detailed_calls
|
|
|
|
"#{calls} (#{cached_calls} cached)"
|
|
|
|
end
|
|
|
|
|
|
|
|
def cached_calls
|
|
|
|
detail_store.count { |item| item[:cached] == 'cached' }
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
def setup_subscribers
|
|
|
|
super
|
|
|
|
|
|
|
|
subscribe('sql.active_record') do |_, start, finish, _, data|
|
2019-12-04 20:38:33 +05:30
|
|
|
if Gitlab::PerformanceBar.enabled_for_request?
|
2021-01-03 14:25:43 +05:30
|
|
|
detail_store << {
|
|
|
|
duration: finish - start,
|
|
|
|
sql: data[:sql].strip,
|
|
|
|
backtrace: Gitlab::BacktraceCleaner.clean_backtrace(caller),
|
|
|
|
cached: data[:cached] ? 'cached' : ''
|
|
|
|
}
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|