forked from MiniProfiler/rack-mini-profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
don't use alias_method since peek-mysql2 uses prepend on rails >= 5 related to MiniProfiler#437 and MiniProfiler#444
- Loading branch information
Showing
1 changed file
with
21 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
# The best kind of instrumentation is in the actual db provider, however we don't want to double instrument | ||
|
||
class Mysql2::Result | ||
alias_method :each_without_profiling, :each | ||
def each(*args, &blk) | ||
return each_without_profiling(*args, &blk) unless defined?(@miniprofiler_sql_id) | ||
module MiniProfiler | ||
def each(*args, &blk) | ||
return super unless defined?(@miniprofiler_sql_id) | ||
|
||
start = Process.clock_gettime(Process::CLOCK_MONOTONIC) | ||
result = each_without_profiling(*args, &blk) | ||
elapsed_time = SqlPatches.elapsed_time(start) | ||
start = Process.clock_gettime(Process::CLOCK_MONOTONIC) | ||
result = super | ||
elapsed_time = SqlPatches.elapsed_time(start) | ||
|
||
@miniprofiler_sql_id.report_reader_duration(elapsed_time) | ||
result | ||
@miniprofiler_sql_id.report_reader_duration(elapsed_time) | ||
result | ||
end | ||
end | ||
|
||
prepend MiniProfiler | ||
end | ||
|
||
class Mysql2::Client | ||
alias_method :query_without_profiling, :query | ||
def query(*args, &blk) | ||
return query_without_profiling(*args, &blk) unless SqlPatches.should_measure? | ||
module MiniProfiler | ||
def query(*args, &blk) | ||
return super unless SqlPatches.should_measure? | ||
|
||
result, record = SqlPatches.record_sql(args[0]) do | ||
query_without_profiling(*args, &blk) | ||
result, record = SqlPatches.record_sql(args[0]) do | ||
super | ||
end | ||
result.instance_variable_set("@miniprofiler_sql_id", record) if result | ||
result | ||
end | ||
result.instance_variable_set("@miniprofiler_sql_id", record) if result | ||
result | ||
end | ||
|
||
prepend MiniProfiler | ||
end |