|
|
@ -9,6 +9,12 @@ module Semantic |
|
|
|
|
|
|
|
def sql(event) |
|
|
|
name = event.payload[:name] |
|
|
|
if name.nil? |
|
|
|
logger.debug ' ', dimensions: Semantic::FancyDimensions.new(rails: '╔═╗', before: 1) |
|
|
|
logger.debug 'could be a migration running by...', event.payload[:sql] |
|
|
|
Rails.logger.info ' ', dimensions: Semantic::FancyDimensions.new(rails: '╚═╝') |
|
|
|
return |
|
|
|
end |
|
|
|
return if IGNORE_PAYLOAD_NAMES.include?(name) |
|
|
|
|
|
|
|
category, model, *remaining = name.split.reverse |
|
|
@ -23,6 +29,10 @@ module Semantic |
|
|
|
statement_taint = TEXT_GRAY_300 |
|
|
|
name = "Cache Read #{model}" |
|
|
|
no_stats = true |
|
|
|
elsif model == ::ActiveRecord::SchemaMigration.to_s |
|
|
|
category_taint = TEXT_MAGENTA |
|
|
|
name = 'Migration required' |
|
|
|
logger.debug ' ', dimensions: Semantic::FancyDimensions.new(rails: '╔═╗', before: 1) |
|
|
|
else |
|
|
|
row_count = event.payload[:row_count] |
|
|
|
name = "Read #{row_count} #{model.pluralize(row_count)}" |
|
|
@ -62,13 +72,19 @@ module Semantic |
|
|
|
|
|
|
|
def pretty_binded_statement(event) |
|
|
|
statement = event.payload[:sql].dup |
|
|
|
bounds = event.payload[:binds].map(&:value) |
|
|
|
bounds = event |
|
|
|
.payload[:binds] |
|
|
|
.select { |item| item.is_a?(::ActiveModel::Attribute) } |
|
|
|
.map(&:value) |
|
|
|
return statement if bounds.empty? |
|
|
|
|
|
|
|
bounds.map { |b| boolean_or_numeric?(b) ? b.to_s : "'#{b}'" } |
|
|
|
.each_with_index { |sb, index| statement.gsub!("$#{index + 1}", sb) } |
|
|
|
statement.gsub!(/ LIMIT 1$/, '') # LIMIT 1 is useless! |
|
|
|
statement |
|
|
|
rescue StandardError => e |
|
|
|
logger.debug event.payload[:binds] |
|
|
|
logger.error 'an error occured during pretty binded statement', e |
|
|
|
end |
|
|
|
|
|
|
|
def boolean_or_numeric?(value) = value.is_a?(Numeric) || value.is_a?(TrueClass) || value.is_a?(FalseClass) |
|
|
|