Sha256: bc55938d17a9b993215a865d402475f3a9b003e7a0edcf81a99a66cebafd0d91
Contents?: true
Size: 1 KB
Versions: 35
Compression:
Stored size: 1 KB
Contents
require 'active_support/notifications' require 'active_record/explain_registry' module ActiveRecord class ExplainSubscriber # :nodoc: def start(name, id, payload) # unused end def finish(name, id, payload) if ExplainRegistry.collect? && !ignore_payload?(payload) ExplainRegistry.queries << payload.values_at(:sql, :binds) end end # SCHEMA queries cannot be EXPLAINed, also we do not want to run EXPLAIN on # our own EXPLAINs no matter how loopingly beautiful that would be. # # On the other hand, we want to monitor the performance of our real database # queries, not the performance of the access to the query cache. IGNORED_PAYLOADS = %w(SCHEMA EXPLAIN CACHE) EXPLAINED_SQLS = /\A\s*(with|select|update|delete|insert)\b/i def ignore_payload?(payload) payload[:exception] || IGNORED_PAYLOADS.include?(payload[:name]) || payload[:sql] !~ EXPLAINED_SQLS end ActiveSupport::Notifications.subscribe("sql.active_record", new) end end
Version data entries
35 entries across 35 versions & 4 rubygems