|
@ -4,20 +4,24 @@ module Semantic |
|
|
class ActiveRecord < LogSubscriber |
|
|
class ActiveRecord < LogSubscriber |
|
|
include AnsiColors |
|
|
include AnsiColors |
|
|
|
|
|
|
|
|
|
|
|
IGNORE_PAYLOAD_NAMES = %w[SCHEMA EXPLAIN].freeze |
|
|
|
|
|
|
|
|
def sql(event) |
|
|
def sql(event) |
|
|
name = event.payload[:name] |
|
|
name = event.payload[:name] |
|
|
return if name == 'SCHEMA' |
|
|
|
|
|
|
|
|
return if IGNORE_PAYLOAD_NAMES.include?(name) |
|
|
|
|
|
|
|
|
sql = event.payload[:sql] |
|
|
|
|
|
cached = event.payload[:cached] |
|
|
|
|
|
row_count = event.payload[:row_count] |
|
|
|
|
|
logger.debug("#{name}: #{sql} cached=#{cached} count=#{row_count}") |
|
|
|
|
|
|
|
|
if name.end_with?('Load') |
|
|
|
|
|
name = event.payload[:cached] ? "#{name} (cached)" : "#{name} (#{event.payload[:row_count]})" |
|
|
|
|
|
end |
|
|
|
|
|
name = colorize(name, TEXT_CYAN) |
|
|
|
|
|
sql = colorize(event.payload[:sql], TEXT_BLUE) |
|
|
|
|
|
logger.debug("#{name} #{sql}") |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def instantiation(event) |
|
|
def instantiation(event) |
|
|
class_name = event.payload[:class_name] |
|
|
|
|
|
record_count = event.payload[:record_count] |
|
|
|
|
|
logger.debug("instantiate #{class_name} #{record_count} times") |
|
|
|
|
|
|
|
|
# class_name = event.payload[:class_name] |
|
|
|
|
|
# record_count = event.payload[:record_count] |
|
|
|
|
|
# logger.debug("instantiate #{class_name} #{record_count} times") |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def strict_loading_violation(event) = any_hook event |
|
|
def strict_loading_violation(event) = any_hook event |
|
|