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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5eb38e8d785a444233248ed07fe7ba2316b947b1b3a779f7738145cff4d56306
4
- data.tar.gz: 8870ff5a0a87c911439618b6d26c9e42a9bb37edcf14182b4067d208774794a9
3
+ metadata.gz: b21dae64f611c7570502547af5c940397cbc247e45f7426f5e349c6308f7fa57
4
+ data.tar.gz: ec130297606a929b7774b350ae74ac0a7e4b66222eeaeaaa5ba7a4e363cd11ae
5
5
  SHA512:
6
- metadata.gz: 15991d0bd081e1b4a35da843c346e2da28196f0fa682a5088de811f37cb027bb57134fc92444ffdd3c6aa29587ff974085d6cb02cf3852a6e23419efd9a8fb94
7
- data.tar.gz: 5fcb874e760ad74bca1c04aa2291c444139dbb441b84ac60dfc5352ae81c1174db7d3e8884aed413919cdb0d5863bf6c0120642f44250481380a5b065319bd0d
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 [Integer] refill_interval Interval in seconds between background tasks that recalculate stale
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 [Integer] cap_interval Interval in seconds between background tasks that enforce the cache size
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 [Integer] retire_interval Interval in seconds between background tasks that remove
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] = true
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[:stale] = false
296
+ h.delete(:stale)
293
297
  h[:ret] = ret
294
298
  end
295
299
  end
data/lib/pgtk/version.rb CHANGED
@@ -11,5 +11,5 @@ require_relative '../pgtk'
11
11
  # License:: MIT
12
12
  module Pgtk
13
13
  # Current version of the library.
14
- VERSION = '0.24.4'
14
+ VERSION = '0.25.0'
15
15
  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.24.4
4
+ version: 0.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko