Class: PG::Connection

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

Instance Method Summary collapse

Instance Method Details

#async_exec(*args, &blk) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/patches/db/pg.rb', line 89

def async_exec(*args,&blk)
  return async_exec_without_profiling(*args,&blk) unless SqlPatches.should_measure?

  start        = Time.now
  result       = exec_without_profiling(*args,&blk)
  elapsed_time = SqlPatches.elapsed_time(start)
  record       = ::Rack::MiniProfiler.record_sql(args[0], elapsed_time)
  result.instance_variable_set("@miniprofiler_sql_id", record) if result

  result
end

#async_exec_without_profilingObject



31
# File 'lib/patches/db/pg.rb', line 31

alias_method :async_exec_without_profiling, :async_exec

#exec(*args, &blk) ⇒ Object Also known as: query



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/patches/db/pg.rb', line 49

def exec(*args,&blk)
  return exec_without_profiling(*args,&blk) unless SqlPatches.should_measure?

  start        = Time.now
  result       = exec_without_profiling(*args,&blk)
  elapsed_time = SqlPatches.elapsed_time(start)
  record       = ::Rack::MiniProfiler.record_sql(args[0], elapsed_time)
  result.instance_variable_set("@miniprofiler_sql_id", record) if result

  result
end

#exec_prepared(*args, &blk) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/patches/db/pg.rb', line 61

def exec_prepared(*args,&blk)
  return exec_prepared_without_profiling(*args,&blk) unless SqlPatches.should_measure?

  start        = Time.now
  result       = exec_prepared_without_profiling(*args,&blk)
  elapsed_time = SqlPatches.elapsed_time(start)
  mapped       = args[0]
  mapped       = @prepare_map[mapped] || args[0] if @prepare_map
  record       = ::Rack::MiniProfiler.record_sql(mapped, elapsed_time)
  result.instance_variable_set("@miniprofiler_sql_id", record) if result

  result
end

#exec_prepared_without_profilingObject



32
# File 'lib/patches/db/pg.rb', line 32

alias_method :exec_prepared_without_profiling, :exec_prepared

#exec_without_profilingObject



30
# File 'lib/patches/db/pg.rb', line 30

alias_method :exec_without_profiling, :exec

#prepare(*args, &blk) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/patches/db/pg.rb', line 36

def prepare(*args,&blk)
  # we have no choice but to do this here,
  # if we do the check for profiling first, our cache may miss critical stuff

  @prepare_map ||= {}
  @prepare_map[args[0]] = args[1]
  # dont leak more than 10k ever
  @prepare_map = {} if @prepare_map.length > 1000

  return prepare_without_profiling(*args,&blk) unless SqlPatches.should_measure?
  prepare_without_profiling(*args,&blk)
end

#prepare_without_profilingObject



34
# File 'lib/patches/db/pg.rb', line 34

alias_method :prepare_without_profiling, :prepare

#send_query_prepared(*args, &blk) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/patches/db/pg.rb', line 75

def send_query_prepared(*args,&blk)
  return send_query_prepared_without_profiling(*args,&blk) unless SqlPatches.should_measure?

  start        = Time.now
  result       = send_query_prepared_without_profiling(*args,&blk)
  elapsed_time = SqlPatches.elapsed_time(start)
  mapped       = args[0]
  mapped       = @prepare_map[mapped] || args[0] if @prepare_map
  record       = ::Rack::MiniProfiler.record_sql(mapped, elapsed_time)
  result.instance_variable_set("@miniprofiler_sql_id", record) if result

  result
end

#send_query_prepared_without_profilingObject



33
# File 'lib/patches/db/pg.rb', line 33

alias_method :send_query_prepared_without_profiling, :send_query_prepared