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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/pgtk/stash.rb +32 -1
- data/lib/pgtk/version.rb +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: 9620e5581d667750f82a36568c6b64fcb27c2c588b93fc433869f1a430159128
|
|
4
|
+
data.tar.gz: 281908df6408d31c7ae69ff9ea4a4122881b7ae54c7906e87d10abf885d625d4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f633a5925cbf6f8ad61247c898a7d58a59d8a64dcf7e23597f625ddfad816e856ae00b6b4960839abec9d763b931a4c519bce49c3bd2724fef38854e7c316c7e
|
|
7
|
+
data.tar.gz: a70e63d0772e40632333d382d4c8598a6a1ab60d72b3ce7bc8675ed12aced75acdc6117fbfccfc6fd9094e927136f7b9f983ba99491b673a392fd7fdb645597a
|
data/Gemfile.lock
CHANGED
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
|
-
|
|
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