debian-mirror-gitlab/lib/peek/views/active_record.rb

44 lines
966 B
Ruby
Raw Normal View History

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
def self.thresholds
@thresholds ||= THRESHOLDS.fetch(Rails.env.to_sym, DEFAULT_THRESHOLDS)
end
2019-10-12 21:52:04 +05:30
private
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?
2019-10-12 21:52:04 +05:30
unless data[:cached]
detail_store << {
duration: finish - start,
sql: data[:sql].strip,
backtrace: Gitlab::Profiler.clean_backtrace(caller)
}
end
end
end
end
end
end
end