pgtk 0.24.4 → 0.25.0
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 +9 -5
- 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: b21dae64f611c7570502547af5c940397cbc247e45f7426f5e349c6308f7fa57
|
|
4
|
+
data.tar.gz: ec130297606a929b7774b350ae74ac0a7e4b66222eeaeaaa5ba7a4e363cd11ae
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 20a6203a23f64e00f9e9bfe9daf44463530820959f70d512d560e3dc0b73e8d9b2b2d453361d37c23a484208630d06654d139518f3188aec0eab18cb4c1817a5
|
|
7
|
+
data.tar.gz: a985cd2ab24bfc68927b46f1852ac1b06f10ad642aac41d23f8294ef66065020796f702f58df8e5c1ae03da8fc1a716a9fcc1c5349a58ee1d983e67b56398374
|
data/lib/pgtk/stash.rb
CHANGED
|
@@ -44,18 +44,19 @@ class Pgtk::Stash
|
|
|
44
44
|
# @param [Object] pool The underlying connection pool that executes actual database queries
|
|
45
45
|
# @param [Hash] stash Internal cache structure containing queries and tables hashes for sharing state
|
|
46
46
|
# across transactions
|
|
47
|
-
# @param [
|
|
47
|
+
# @param [Float] refill_interval Interval in seconds between background tasks that recalculate stale
|
|
48
48
|
# cached queries
|
|
49
|
+
# @param [Float] refill_delay A pause in seconds we take before making a refill
|
|
49
50
|
# @param [Integer] max_queue_length Maximum number of refilling tasks allowed in the thread pool queue
|
|
50
51
|
# before new tasks are skipped
|
|
51
52
|
# @param [Integer] threads Number of worker threads in the background thread pool for cache refilling
|
|
52
53
|
# operations
|
|
53
54
|
# @param [Integer] cap Maximum number of cached query results to retain; oldest queries are evicted when
|
|
54
55
|
# this limit is exceeded
|
|
55
|
-
# @param [
|
|
56
|
+
# @param [Float] cap_interval Interval in seconds between background tasks that enforce the cache size
|
|
56
57
|
# cap by removing old queries
|
|
57
58
|
# @param [Integer] retire Maximum age in seconds to keep a query in cache after its latest usage
|
|
58
|
-
# @param [
|
|
59
|
+
# @param [Float] retire_interval Interval in seconds between background tasks that remove
|
|
59
60
|
# retired queries
|
|
60
61
|
# @param [Loog] loog Logger instance for debugging and monitoring cache operations (default: null logger)
|
|
61
62
|
# @param [Concurrent::ReentrantReadWriteLock] entrance Read-write lock for thread-safe cache access
|
|
@@ -66,6 +67,7 @@ class Pgtk::Stash
|
|
|
66
67
|
pool,
|
|
67
68
|
stash: { queries: {}, tables: {} },
|
|
68
69
|
refill_interval: 16,
|
|
70
|
+
refill_delay: 0,
|
|
69
71
|
max_queue_length: 128,
|
|
70
72
|
threads: 4,
|
|
71
73
|
cap: 10_000,
|
|
@@ -81,6 +83,7 @@ class Pgtk::Stash
|
|
|
81
83
|
@launched = launched
|
|
82
84
|
@entrance = entrance
|
|
83
85
|
@refill_interval = refill_interval
|
|
86
|
+
@refill_delay = refill_delay
|
|
84
87
|
@max_queue_length = max_queue_length
|
|
85
88
|
@threads = threads
|
|
86
89
|
@cap = cap
|
|
@@ -177,7 +180,7 @@ class Pgtk::Stash
|
|
|
177
180
|
tables.each do |t|
|
|
178
181
|
@stash[:tables][t]&.each do |q|
|
|
179
182
|
@stash[:queries][q]&.each_key do |key|
|
|
180
|
-
@stash[:queries][q][key][:stale] =
|
|
183
|
+
@stash[:queries][q][key][:stale] = Time.now
|
|
181
184
|
end
|
|
182
185
|
end
|
|
183
186
|
end
|
|
@@ -283,13 +286,14 @@ class Pgtk::Stash
|
|
|
283
286
|
q = a[0]
|
|
284
287
|
@stash[:queries][q].each_key do |k|
|
|
285
288
|
next unless @stash[:queries][q][k][:stale]
|
|
289
|
+
next if @stash[:queries][q][k][:stale] > Time.now - @refill_delay
|
|
286
290
|
next if @tpool.queue_length >= @max_queue_length
|
|
287
291
|
@tpool.post do
|
|
288
292
|
h = @stash[:queries][q][k]
|
|
289
293
|
ret = @pool.exec(q, h[:params], h[:result])
|
|
290
294
|
@entrance.with_write_lock do
|
|
291
295
|
h = @stash[:queries][q][k]
|
|
292
|
-
h
|
|
296
|
+
h.delete(:stale)
|
|
293
297
|
h[:ret] = ret
|
|
294
298
|
end
|
|
295
299
|
end
|
data/lib/pgtk/version.rb
CHANGED