pgtk 0.31.6 → 0.31.7

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: 117996e543551102eebf83be228996818dbfdbfc324f7f45b5d346a57d39fc1a
4
- data.tar.gz: 22bd0738c88e60ed29ad3310a87755709dc4512d6b92932c88442253c29847f3
3
+ metadata.gz: 9620e5581d667750f82a36568c6b64fcb27c2c588b93fc433869f1a430159128
4
+ data.tar.gz: 281908df6408d31c7ae69ff9ea4a4122881b7ae54c7906e87d10abf885d625d4
5
5
  SHA512:
6
- metadata.gz: 0ae1185f452400e2f2f984e5266bdb9c6b8dc7d92b798eb714d18903949f230d8707911b562431984f4fa52178dc52198bfeac5b24d2aaeff918ee0b36804541
7
- data.tar.gz: 4b8fc6853d556967173556f0067a6c611b4a93be0440c31659b0892f7d944606fbc19f15e27b1361b06cacea99e268bb81008893dfcc910e56103c10d0b9c42c
6
+ metadata.gz: f633a5925cbf6f8ad61247c898a7d58a59d8a64dcf7e23597f625ddfad816e856ae00b6b4960839abec9d763b931a4c519bce49c3bd2724fef38854e7c316c7e
7
+ data.tar.gz: a70e63d0772e40632333d382d4c8598a6a1ab60d72b3ce7bc8675ed12aced75acdc6117fbfccfc6fd9094e927136f7b9f983ba99491b673a392fd7fdb645597a
data/Gemfile.lock CHANGED
@@ -81,7 +81,7 @@ GEM
81
81
  pg (1.6.3-x86_64-linux)
82
82
  pg (1.6.3-x86_64-linux-musl)
83
83
  prism (1.9.0)
84
- qbash (0.8.2)
84
+ qbash (0.8.3)
85
85
  backtrace (> 0)
86
86
  elapsed (> 0)
87
87
  loog (> 0)
data/lib/pgtk/stash.rb CHANGED
@@ -89,6 +89,7 @@ class Pgtk::Stash
89
89
  # @return [void]
90
90
  def start!
91
91
  @pool.start!
92
+ cascade!
92
93
  launch!
93
94
  end
94
95
 
@@ -218,8 +219,9 @@ class Pgtk::Stash
218
219
  tables.uniq!
219
220
  ret = @pool.exec(pure, params, result)
220
221
  now = Time.now
222
+ affected = (tables + tables.flat_map { |t| @cascades&.fetch(t, []) || [] }).uniq
221
223
  @entrance.with_write_lock do
222
- tables.each do |t|
224
+ affected.each do |t|
223
225
  @stash[:table_mod][t] = now
224
226
  @stash[:tables][t]&.each do |q|
225
227
  @stash[:queries][q]&.each_key do |key|
@@ -280,6 +282,35 @@ class Pgtk::Stash
280
282
  end
281
283
  end
282
284
 
285
+ # Discover ON DELETE CASCADE / ON UPDATE CASCADE foreign keys so that a
286
+ # modify on the parent table also invalidates cached queries on children.
287
+ #
288
+ # @return [nil]
289
+ def cascade!
290
+ direct = Hash.new { |h, k| h[k] = [] }
291
+ @pool.exec(<<~SQL).each { |r| direct[r['parent']] << r['child'] }
292
+ SELECT tc.table_name AS child, ccu.table_name AS parent
293
+ FROM information_schema.table_constraints tc
294
+ JOIN information_schema.referential_constraints rc
295
+ ON tc.constraint_name = rc.constraint_name
296
+ AND tc.table_schema = rc.constraint_schema
297
+ JOIN information_schema.constraint_column_usage ccu
298
+ ON ccu.constraint_name = tc.constraint_name
299
+ AND ccu.table_schema = tc.table_schema
300
+ WHERE tc.constraint_type = 'FOREIGN KEY'
301
+ AND (rc.delete_rule = 'CASCADE' OR rc.update_rule = 'CASCADE')
302
+ AND tc.table_schema NOT IN ('pg_catalog', 'information_schema')
303
+ SQL
304
+ @cascades = direct.keys.to_h { |p| [p, transitive(p, direct, []).uniq] }
305
+ nil
306
+ end
307
+
308
+ def transitive(parent, direct, seen)
309
+ return [] if seen.include?(parent)
310
+ seen << parent
311
+ direct[parent].flat_map { |c| [c] + transitive(c, direct, seen) }
312
+ end
313
+
283
314
  # Launch background tasks for cache management.
284
315
  #
285
316
  # @return [nil]
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.31.6' unless defined?(VERSION)
13
+ VERSION = '0.31.7' unless defined?(VERSION)
14
14
  end
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.31.6
4
+ version: 0.31.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko