Class: Rack::MiniProfiler::NoBrainerProfiler

Inherits:
Object
  • Object
show all
Defined in:
lib/patches/db/nobrainer.rb

Instance Method Summary collapse

Instance Method Details

#on_query(env) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/patches/db/nobrainer.rb', line 3

def on_query(env)
  if SqlPatches.should_measure?
    not_indexed = env[:criteria] && env[:criteria].where_present? &&
                      !env[:criteria].where_indexed? &&
                      !env[:criteria].model.try(:perf_warnings_disabled)

    query = ""

    # per-model/query database overrides
    query << "[#{env[:options][:db]}] " if env[:options][:db]

    # "read", "write" prefix
    # query << "(#{NoBrainer::RQL.type_of(env[:query]).to_s}) "

    query << "NOT USING INDEX: " if not_indexed
    query << env[:query].inspect.gsub(/\n/, '').gsub(/ +/, ' ') + " "

    if env[:exception]
      query << "exception: #{env[:exception].class} #{env[:exception].message.split("\n").first} "
    end

    ::Rack::MiniProfiler.record_sql query.strip, env[:duration] * 1000.0
  end
end