Module: Rack::MiniProfiler::ActiveRecordInstrumentation

Defined in:
lib/patches/sql_patches.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(instrumented_class) ⇒ Object



140
141
142
143
144
145
146
147
148
# File 'lib/patches/sql_patches.rb', line 140

def self.included(instrumented_class)
  instrumented_class.class_eval do
    unless instrumented_class.method_defined?(:log_without_miniprofiler)
      alias_method :log_without_miniprofiler, :log
      alias_method :log, :log_with_miniprofiler
      protected :log
    end
  end
end

Instance Method Details

#log_with_miniprofiler(*args, &block) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/patches/sql_patches.rb', line 150

def log_with_miniprofiler(*args, &block)
  current = ::Rack::MiniProfiler.current
  return log_without_miniprofiler(*args, &block) unless current

  sql, name, binds = args
  t0 = Time.now
  rval = log_without_miniprofiler(*args, &block)
  
  # Don't log schema queries if the option is set
  return rval if Rack::MiniProfiler.config.skip_schema_queries and name =~ /SCHEMA/

  elapsed_time = ((Time.now - t0).to_f * 1000).round(1)
  Rack::MiniProfiler.record_sql(sql, elapsed_time)
  rval
end