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 +4 -4
- data/Gemfile.lock +10 -10
- data/lib/pgtk/stash.rb +39 -18
- data/lib/pgtk/version.rb +1 -1
- data/resources/pom.xml +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 72cdeed11d9faa8c9097c01256603b2ce77a507b936c983ab623b9e1d6e7d364
|
|
4
|
+
data.tar.gz: ab60b5670e87009e1eb47983bd8d729eb403d78a9c6a20c82ea14d70d4a7d18f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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.
|
|
55
|
+
nokogiri (1.19.3-aarch64-linux-gnu)
|
|
56
56
|
racc (~> 1.4)
|
|
57
|
-
nokogiri (1.19.
|
|
57
|
+
nokogiri (1.19.3-aarch64-linux-musl)
|
|
58
58
|
racc (~> 1.4)
|
|
59
|
-
nokogiri (1.19.
|
|
59
|
+
nokogiri (1.19.3-arm-linux-gnu)
|
|
60
60
|
racc (~> 1.4)
|
|
61
|
-
nokogiri (1.19.
|
|
61
|
+
nokogiri (1.19.3-arm-linux-musl)
|
|
62
62
|
racc (~> 1.4)
|
|
63
|
-
nokogiri (1.19.
|
|
63
|
+
nokogiri (1.19.3-arm64-darwin)
|
|
64
64
|
racc (~> 1.4)
|
|
65
|
-
nokogiri (1.19.
|
|
65
|
+
nokogiri (1.19.3-x86_64-darwin)
|
|
66
66
|
racc (~> 1.4)
|
|
67
|
-
nokogiri (1.19.
|
|
67
|
+
nokogiri (1.19.3-x86_64-linux-gnu)
|
|
68
68
|
racc (~> 1.4)
|
|
69
|
-
nokogiri (1.19.
|
|
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.
|
|
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(
|
|
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
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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(
|
|
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
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
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
data/resources/pom.xml
CHANGED