pgtk 0.32.2 → 0.32.4

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: b48e3fb20daadf888fd4bbf448b1cd3463ec8205030cb33f05041cac725050fb
4
- data.tar.gz: deba6c857216fc73285e4a68535a6aff8ead236849c470977e6904178497dc27
3
+ metadata.gz: 72cdeed11d9faa8c9097c01256603b2ce77a507b936c983ab623b9e1d6e7d364
4
+ data.tar.gz: ab60b5670e87009e1eb47983bd8d729eb403d78a9c6a20c82ea14d70d4a7d18f
5
5
  SHA512:
6
- metadata.gz: dcf47d0d6145eba4cea340dbdc69bba939c84afad4da5a7aa9af2026cfc36d4b7a0dc29528e1a5cf5ed73ed45afaaaf1b1b64b6c52e36346c7a879cf8f13e77c
7
- data.tar.gz: ea608bf12ae7334187830312d04d6954dc7f6071d49b9e6796a4a2b5b6fbbe219a836445ba208873f95d16bb31c7c9d866cf0fb20c1af92fa7ffbbd9d8b128ad
6
+ metadata.gz: 691ea0c8b5ca6002b72ab4b66487b3dbf489feaedbc8e80cc772fe69cfc1ad966fa836e13298b561cadb38c75290ed8a533a389751a7d6b0454da23b87afcb74
7
+ data.tar.gz: 8a04b05ad839b935ac3f8e5362bb957eb64e8e70e1b963c5713a7c7755f8184e6c1e8c806a4d03467bba80e3ce5af0cf9c1a1a50c4d73f11e79d46dc9569fc2f
data/Gemfile.lock CHANGED
@@ -35,7 +35,7 @@ GEM
35
35
  tago (~> 0.1)
36
36
  ellipsized (0.3.0)
37
37
  joined (0.4.0)
38
- json (2.19.4)
38
+ json (2.19.5)
39
39
  language_server-protocol (3.17.0.5)
40
40
  lint_roller (1.1.0)
41
41
  logger (1.7.0)
@@ -52,21 +52,21 @@ GEM
52
52
  minitest (>= 5.0, < 7)
53
53
  ruby-progressbar
54
54
  minitest-stub-const (0.6)
55
- nokogiri (1.19.2-aarch64-linux-gnu)
55
+ nokogiri (1.19.3-aarch64-linux-gnu)
56
56
  racc (~> 1.4)
57
- nokogiri (1.19.2-aarch64-linux-musl)
57
+ nokogiri (1.19.3-aarch64-linux-musl)
58
58
  racc (~> 1.4)
59
- nokogiri (1.19.2-arm-linux-gnu)
59
+ nokogiri (1.19.3-arm-linux-gnu)
60
60
  racc (~> 1.4)
61
- nokogiri (1.19.2-arm-linux-musl)
61
+ nokogiri (1.19.3-arm-linux-musl)
62
62
  racc (~> 1.4)
63
- nokogiri (1.19.2-arm64-darwin)
63
+ nokogiri (1.19.3-arm64-darwin)
64
64
  racc (~> 1.4)
65
- nokogiri (1.19.2-x86_64-darwin)
65
+ nokogiri (1.19.3-x86_64-darwin)
66
66
  racc (~> 1.4)
67
- nokogiri (1.19.2-x86_64-linux-gnu)
67
+ nokogiri (1.19.3-x86_64-linux-gnu)
68
68
  racc (~> 1.4)
69
- nokogiri (1.19.2-x86_64-linux-musl)
69
+ nokogiri (1.19.3-x86_64-linux-musl)
70
70
  racc (~> 1.4)
71
71
  os (1.1.4)
72
72
  parallel (2.0.1)
@@ -94,7 +94,7 @@ GEM
94
94
  tago (~> 0.0)
95
95
  regexp_parser (2.12.0)
96
96
  rexml (3.4.4)
97
- rubocop (1.86.1)
97
+ rubocop (1.86.2)
98
98
  json (~> 2.3)
99
99
  language_server-protocol (~> 3.17.0.2)
100
100
  lint_roller (~> 1.1.0)
data/lib/pgtk/stash.rb CHANGED
@@ -32,12 +32,16 @@ class Pgtk::Stash
32
32
  MODS = %w[INSERT DELETE UPDATE LOCK VACUUM TRANSACTION COMMIT ROLLBACK REINDEX TRUNCATE CREATE ALTER DROP SET].freeze
33
33
  MODS_RE = Regexp.new("(^|\\s)(#{MODS.join('|')})(\\s|$)")
34
34
 
35
+ IDENT = '[a-z_][a-z0-9_]*'
36
+
35
37
  ALTS = ['UPDATE', 'INSERT INTO', 'DELETE FROM', 'TRUNCATE', 'ALTER TABLE', 'DROP TABLE'].freeze
36
- ALTS_RE = Regexp.new("(?<=^|\\s)(?:#{ALTS.join('|')})\\s([a-z]+)(?=[^a-z]|$)")
38
+ ALTS_RE = Regexp.new("(?<=^|\\s)(?:#{ALTS.join('|')})\\s(#{IDENT})(?=[^a-z0-9_]|$)")
39
+
40
+ READS_RE = Regexp.new("(?<=^|\\s)(?:FROM|JOIN)\\s(#{IDENT})(?=\\s|;|$)")
37
41
 
38
42
  SEPARATOR = ' --%*@#~($-- '
39
43
 
40
- private_constant :MODS, :ALTS, :MODS_RE, :ALTS_RE, :SEPARATOR
44
+ private_constant :MODS, :ALTS, :IDENT, :MODS_RE, :ALTS_RE, :READS_RE, :SEPARATOR
41
45
 
42
46
  # Initialize a new Stash with query caching.
43
47
  #
@@ -57,7 +61,7 @@ class Pgtk::Stash
57
61
  # @param [Concurrent::ReentrantReadWriteLock] entrance Read-write lock for thread-safe access
58
62
  def initialize(
59
63
  pool,
60
- stash: { queries: {}, tables: {}, table_mod: {} },
64
+ stash: { queries: {}, tables: {}, table_mod: {}, table_inflight: {} },
61
65
  loog: Loog::NULL,
62
66
  entrance: Concurrent::ReentrantReadWriteLock.new,
63
67
  refill: 16,
@@ -72,6 +76,7 @@ class Pgtk::Stash
72
76
  @pool = pool
73
77
  @stash = stash
74
78
  @stash[:table_mod] ||= {}
79
+ @stash[:table_inflight] ||= {}
75
80
  @loog = loog
76
81
  @entrance = entrance
77
82
  @refill = refill
@@ -217,29 +222,40 @@ class Pgtk::Stash
217
222
  def modify(pure, params, result)
218
223
  tables = pure.scan(ALTS_RE).flatten
219
224
  tables.uniq!
220
- ret = @pool.exec(pure, params, result)
221
- now = Time.now
222
225
  affected = (tables + tables.flat_map { |t| @cascades&.fetch(t, []) || [] }).uniq
223
226
  @entrance.with_write_lock do
224
- affected.each do |t|
225
- old = @stash[:table_mod][t]
226
- stamp = old && old > now ? old : now
227
- @stash[:table_mod][t] = stamp
228
- @stash[:tables][t]&.each do |q|
229
- @stash[:queries][q]&.each_key do |key|
230
- @stash[:queries][q][key][:stale] = stamp
227
+ affected.each { |t| @stash[:table_inflight][t] = (@stash[:table_inflight][t] || 0) + 1 }
228
+ end
229
+ begin
230
+ ret = @pool.exec(pure, params, result)
231
+ now = Time.now
232
+ @entrance.with_write_lock do
233
+ affected.each do |t|
234
+ @stash[:table_inflight][t] -= 1
235
+ old = @stash[:table_mod][t]
236
+ stamp = old && old > now ? old : now
237
+ @stash[:table_mod][t] = stamp
238
+ @stash[:tables][t]&.each do |q|
239
+ @stash[:queries][q]&.each_key do |key|
240
+ @stash[:queries][q][key][:stale] = stamp
241
+ end
231
242
  end
232
243
  end
233
244
  end
245
+ ret
246
+ rescue StandardError
247
+ @entrance.with_write_lock do
248
+ affected.each { |t| @stash[:table_inflight][t] -= 1 }
249
+ end
250
+ raise
234
251
  end
235
- ret
236
252
  end
237
253
 
238
254
  def select(pure, params, result)
239
255
  key = params.join(SEPARATOR)
240
256
  ret = @stash.dig(:queries, pure, key, :ret)
241
257
  if ret.nil? || @stash.dig(:queries, pure, key, :stale)
242
- tables = pure.scan(/(?<=^|\s)(?:FROM|JOIN) ([a-z_]+)(?=\s|;|$)/).flatten
258
+ tables = pure.scan(READS_RE).flatten
243
259
  tables.uniq!
244
260
  marks = tables.to_h { |t| [t, @stash[:table_mod][t]] }
245
261
  ret = @pool.exec(pure, params, result)
@@ -376,8 +392,12 @@ class Pgtk::Stash
376
392
  end
377
393
 
378
394
  def replenish(query)
395
+ tables = query.scan(READS_RE).flatten
396
+ tables.uniq!
397
+ pinned = nil
379
398
  snapshot =
380
399
  @entrance.with_read_lock do
400
+ pinned = tables.to_h { |t| [t, @stash[:table_mod][t]] }
381
401
  @stash[:queries][query]&.filter_map do |k, h|
382
402
  next unless h[:stale]
383
403
  next if h[:stale] > Time.now - @delay
@@ -392,10 +412,11 @@ class Pgtk::Stash
392
412
  @entrance.with_write_lock do
393
413
  h = @stash[:queries][query]&.dig(k)
394
414
  next unless h
395
- if h[:stale] == mark
396
- h[:ret] = ret
397
- h.delete(:stale)
398
- end
415
+ next unless h[:stale] == mark
416
+ next if pinned.any? { |t, m| @stash[:table_mod][t] != m }
417
+ next if tables.any? { |t| (@stash[:table_inflight][t] || 0).positive? }
418
+ h[:ret] = ret
419
+ h.delete(:stale)
399
420
  end
400
421
  end
401
422
  end
data/lib/pgtk/version.rb CHANGED
@@ -10,5 +10,5 @@ require_relative '../pgtk'
10
10
  # Copyright:: Copyright (c) 2019-2026 Yegor Bugayenko
11
11
  # License:: MIT
12
12
  module Pgtk
13
- VERSION = '0.32.2' unless defined?(VERSION)
13
+ VERSION = '0.32.4' unless defined?(VERSION)
14
14
  end
data/resources/pom.xml CHANGED
@@ -11,7 +11,7 @@
11
11
  <packaging>pom</packaging>
12
12
  <properties>
13
13
  <postgresql.version>42.7.11</postgresql.version>
14
- <liquibase.version>5.0.2</liquibase.version>
14
+ <liquibase.version>5.0.3</liquibase.version>
15
15
  </properties>
16
16
  <dependencies>
17
17
  <dependency>
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.32.2
4
+ version: 0.32.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko