Sha256: cb2527e0d511466b6844d1868fa9352486b04f6d6db8495860b61e0e839b68a3

Contents?: true

Size: 764 Bytes

Versions: 11

Compression:

Stored size: 764 Bytes

Contents

# frozen_string_literal: true

class Mysql2::Result
  module MiniProfiler
    def each(*args, &blk)
      return super unless defined?(@miniprofiler_sql_id)

      start        = Process.clock_gettime(Process::CLOCK_MONOTONIC)
      result       = super
      elapsed_time = SqlPatches.elapsed_time(start)

      @miniprofiler_sql_id.report_reader_duration(elapsed_time)
      result
    end
  end

  prepend MiniProfiler
end

class Mysql2::Client
  module MiniProfiler
    def query(*args, &blk)
      return super unless SqlPatches.should_measure?

      result, record = SqlPatches.record_sql(args[0]) do
        super
      end
      result.instance_variable_set("@miniprofiler_sql_id", record) if result
      result
    end
  end

  prepend MiniProfiler
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rack-mini-profiler-3.3.1 lib/patches/db/mysql2/prepend.rb
rack-mini-profiler-3.3.0 lib/patches/db/mysql2/prepend.rb
rack-mini-profiler-3.2.1 lib/patches/db/mysql2/prepend.rb
rack-mini-profiler-3.2.0 lib/patches/db/mysql2/prepend.rb
rack-mini-profiler-3.1.1 lib/patches/db/mysql2/prepend.rb
rack-mini-profiler-3.1.0 lib/patches/db/mysql2/prepend.rb
rack-mini-profiler-3.0.0 lib/patches/db/mysql2/prepend.rb
rack-mini-profiler-2.3.4 lib/patches/db/mysql2/prepend.rb
rack-mini-profiler-2.3.3 lib/patches/db/mysql2/prepend.rb
rack-mini-profiler-2.3.2 lib/patches/db/mysql2/prepend.rb
rack-mini-profiler-2.3.1 lib/patches/db/mysql2/prepend.rb