pgtk 0.32.0 → 0.32.1
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/lib/pgtk/stash.rb +11 -6
- 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: 99d205db0612071b4a609acd0cc94bea3c032742cf3bacbe37aa05c8213a88f3
|
|
4
|
+
data.tar.gz: f9ba543f04eb5639d276472ab2cc8a5ab0c9a714a22f8b042d1b6d63d2b5b51b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3a3e45f7f09b28830164913bc952d6835f3deeab8f6e02f984a9364d694ea3eca82dd6924da8d3378317e46db55997c82834804eb342a140b3646ee73f56ab0d
|
|
7
|
+
data.tar.gz: f5f76023aee057117b9e03fece17928a76c628e8371d3e94d6cccff0ad5a86695585aae0b7f5350653f7ecfa31aee93c2ba3f68088518e94716bc5183ab4f5db
|
data/lib/pgtk/stash.rb
CHANGED
|
@@ -222,7 +222,8 @@ class Pgtk::Stash
|
|
|
222
222
|
affected = (tables + tables.flat_map { |t| @cascades&.fetch(t, []) || [] }).uniq
|
|
223
223
|
@entrance.with_write_lock do
|
|
224
224
|
affected.each do |t|
|
|
225
|
-
@stash[:table_mod][t]
|
|
225
|
+
old = @stash[:table_mod][t]
|
|
226
|
+
@stash[:table_mod][t] = old && old > now ? old : now
|
|
226
227
|
@stash[:tables][t]&.each do |q|
|
|
227
228
|
@stash[:queries][q]&.each_key do |key|
|
|
228
229
|
@stash[:queries][q][key][:stale] = now
|
|
@@ -237,18 +238,17 @@ class Pgtk::Stash
|
|
|
237
238
|
key = params.join(SEPARATOR)
|
|
238
239
|
ret = @stash.dig(:queries, pure, key, :ret)
|
|
239
240
|
if ret.nil? || @stash.dig(:queries, pure, key, :stale)
|
|
240
|
-
mark = @stash.dig(:queries, pure, key, :stale)
|
|
241
241
|
tables = pure.scan(/(?<=^|\s)(?:FROM|JOIN) ([a-z_]+)(?=\s|;|$)/).flatten
|
|
242
242
|
tables.uniq!
|
|
243
243
|
marks = tables.to_h { |t| [t, @stash[:table_mod][t]] }
|
|
244
244
|
ret = @pool.exec(pure, params, result)
|
|
245
|
-
cache(pure, key, params, result, ret,
|
|
245
|
+
cache(pure, key, params, result, ret, tables, marks) unless pure.include?(' NOW() ')
|
|
246
246
|
end
|
|
247
247
|
bump(pure, key) if @stash.dig(:queries, pure, key)
|
|
248
248
|
ret
|
|
249
249
|
end
|
|
250
250
|
|
|
251
|
-
def cache(pure, key, params, result, ret,
|
|
251
|
+
def cache(pure, key, params, result, ret, tables, marks)
|
|
252
252
|
raise(ArgumentError, "No tables at #{pure.inspect}") if tables.empty?
|
|
253
253
|
@entrance.with_write_lock do
|
|
254
254
|
tables.each do |t|
|
|
@@ -257,10 +257,15 @@ class Pgtk::Stash
|
|
|
257
257
|
end
|
|
258
258
|
@stash[:queries][pure] ||= {}
|
|
259
259
|
existing = @stash[:queries][pure][key]
|
|
260
|
-
stale = existing && existing[:stale]
|
|
261
260
|
stillborn = tables.any? { |t| (cur = @stash[:table_mod][t]) && cur != marks[t] }
|
|
262
261
|
entry = { ret:, params:, result:, used: Time.now }
|
|
263
|
-
entry[:stale] =
|
|
262
|
+
entry[:stale] =
|
|
263
|
+
if existing && existing[:stale]
|
|
264
|
+
existing[:stale]
|
|
265
|
+
elsif stillborn
|
|
266
|
+
Time.now
|
|
267
|
+
end
|
|
268
|
+
entry.delete(:stale) if entry[:stale].nil?
|
|
264
269
|
@stash[:queries][pure][key] = entry
|
|
265
270
|
end
|
|
266
271
|
end
|
data/lib/pgtk/version.rb
CHANGED