Class: PG::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/peek/views/pg.rb

Overview

Instrument SQL time

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.query_countObject

Returns the value of attribute query_count.



7
8
9
# File 'lib/peek/views/pg.rb', line 7

def query_count
  @query_count
end

.query_timeObject

Returns the value of attribute query_time.



7
8
9
# File 'lib/peek/views/pg.rb', line 7

def query_time
  @query_time
end

Instance Method Details

#async_exec_with_timing(*args) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/peek/views/pg.rb', line 22

def async_exec_with_timing(*args)
  start = Time.now
  async_exec_without_timing(*args)
ensure
  duration = (Time.now - start)
  PG::Connection.query_time.update { |value| value + duration }
  PG::Connection.query_count.update { |value| value + 1 }
end

#exec_with_timing(*args) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/peek/views/pg.rb', line 12

def exec_with_timing(*args)
  start = Time.now
  exec_without_timing(*args)
ensure
  duration = (Time.now - start)
  PG::Connection.query_time.update { |value| value + duration }
  PG::Connection.query_count.update { |value| value + 1 }
end