pgtk 0.16.3 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f86b9a969a2e41e480e4596035128c5ac1f260eeaa4dfb0625a88316d5c34f5d
4
- data.tar.gz: d6b9dfe1dd5717f2884ba63d72b87696ddc0331983527dbb530f74a469961af6
3
+ metadata.gz: 8a1ac7d09cdc700a6fa51f239d1f14564f14f9cee56773a933e7e7d310291b1a
4
+ data.tar.gz: 8bcce91182b85e2a592cd3031048b9687b56c7be0587eda199b1c97df944f630
5
5
  SHA512:
6
- metadata.gz: 7f7433c8b02fae500929e2e62929469eae1511d958fb85d8d7a6ca56fe9010467bac3759b6f77155ec4e4d86f92b532e8f7c5bf57c83f4c6a7ce99caebc63b9d
7
- data.tar.gz: ef3a0849da8ac6678a4957868618b6c6350c86fc255285e49efd6ed3cc8dbc5503765a54abed9387d60a90e0d1c1571dd5f35e4f2daad4e8c9b5ada8e141b1d5
6
+ metadata.gz: '018f2c1cc65ca5b64f27609e4934f47163dcd8c4e582508e995dd332992b18f652de8fef63a9f5d86af969ce306796d2e2db0f490072933ab7a38cd91d02cfa0'
7
+ data.tar.gz: 16c2631220d3cdad2aef2132213a79c922aae79edad0d34b9b7003bd5eec62977cbf9f3febb20a99b17612e77c074e64b7305078903b76e156e27bb90bfbb69c
@@ -59,9 +59,11 @@ class Pgtk::Impatient
59
59
  #
60
60
  # @param [Pgtk::Pool] pool The pool to decorate
61
61
  # @param [Integer] timeout Timeout in seconds for each SQL query
62
- def initialize(pool, timeout = 1)
62
+ # @param [Array<Regex>] off List of regex to exclude queries from checking
63
+ def initialize(pool, timeout, *off)
63
64
  @pool = pool
64
65
  @timeout = timeout
66
+ @off = off
65
67
  end
66
68
 
67
69
  # Get the version of PostgreSQL server.
@@ -78,6 +80,7 @@ class Pgtk::Impatient
78
80
  # @return [Array] Result rows
79
81
  # @raise [Timeout::Error] If the query takes too long
80
82
  def exec(sql, *args)
83
+ return @pool.exec(sql, *args) if @off.any? { |re| re.match?(sql) }
81
84
  start = Time.now
82
85
  begin
83
86
  Timeout.timeout(@timeout) do
data/lib/pgtk/version.rb CHANGED
@@ -11,5 +11,5 @@ require_relative '../pgtk'
11
11
  # License:: MIT
12
12
  module Pgtk
13
13
  # Current version of the library.
14
- VERSION = '0.16.3'
14
+ VERSION = '0.17.0'
15
15
  end
@@ -20,7 +20,7 @@ require_relative '../lib/pgtk/impatient'
20
20
  class TestImpatient < Pgtk::Test
21
21
  def test_takes_version
22
22
  fake_pool do |pool|
23
- v = Pgtk::Impatient.new(pool).version
23
+ v = Pgtk::Impatient.new(pool, 1).version
24
24
  refute_nil(v)
25
25
  end
26
26
  end
@@ -28,16 +28,24 @@ class TestImpatient < Pgtk::Test
28
28
  def test_interrupts
29
29
  fake_pool do |pool|
30
30
  assert_raises(Pgtk::Impatient::TooSlow) do
31
- Pgtk::Impatient.new(pool, 0.1).exec(
32
- 'SELECT COUNT(*) FROM generate_series(1, 10000000) AS a'
31
+ Pgtk::Impatient.new(pool, 0.01).exec(
32
+ 'SELECT COUNT(*) FROM generate_series(1, 1000000) AS a'
33
33
  )
34
34
  end
35
35
  end
36
36
  end
37
37
 
38
+ def test_skips_by_regex
39
+ fake_pool do |pool|
40
+ Pgtk::Impatient.new(pool, 0.01, /^SELECT.*$/).exec(
41
+ 'SELECT COUNT(*) FROM generate_series(1, 1000000) AS a'
42
+ )
43
+ end
44
+ end
45
+
38
46
  def test_doesnt_interrupt
39
47
  fake_pool do |pool|
40
- id = Pgtk::Impatient.new(pool).exec(
48
+ id = Pgtk::Impatient.new(pool, 1).exec(
41
49
  'INSERT INTO book (title) VALUES ($1) RETURNING id',
42
50
  ['1984']
43
51
  ).first['id'].to_i
@@ -47,7 +55,7 @@ class TestImpatient < Pgtk::Test
47
55
 
48
56
  def test_doesnt_interrupt_in_transaction
49
57
  fake_pool do |pool|
50
- Pgtk::Impatient.new(pool).transaction do |t|
58
+ Pgtk::Impatient.new(pool, 1).transaction do |t|
51
59
  id = t.exec(
52
60
  'INSERT INTO book (title) VALUES ($1) RETURNING id',
53
61
  ['1984']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.3
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko