waterdrop 2.8.10 → 2.8.11

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: 8ed8d57d7b79987870f918e97b3ffeee07c6c68b75a506bd11f29abe8778f21f
4
- data.tar.gz: 86fe1bdb3d1963ef3783a254dbf0c7ae3ad61dc5608eeca5a41dcc2bbd454c1b
3
+ metadata.gz: 3dc4cc4d1928a447c4e6c3ab9d268a87c0d3a462b1b9d62685fe51168842c0e1
4
+ data.tar.gz: b82300c02b3d774aba5a2a354f7b9d0d11f2d08738ccf66348185f1a4bbd1605
5
5
  SHA512:
6
- metadata.gz: 22949a9ec65e4e6c0532ad469747989c4971de5320c705cf704371440b2d21b6edd83504eb77e56192ec0043c04334c91892813f3b1d01418e88d1f996064949
7
- data.tar.gz: 9cecd0e2e56209d14eac2c896d9f2086973874de78e478e758404eb31d17e1b9abcf66e54011a1e9341dad215bac5de8fdafcc29ef38e0a6c8f43ca8eb82a301
6
+ metadata.gz: a2f0d2befaa70b25bf756fdee15757328cfa0d2a642243100ae89421c0b0d65ce7b3b3d94d630f90cf040b7bb3ce2218aaee8200edfdfc96164038fee6d79e9b
7
+ data.tar.gz: 2b5a2fae3f060435c697024aab1c064342d9919b03304b8c29a1ee25c0d85533a0b43af5184c4dd8ceb5d49377178536ca6b0306af473ed4876dc98f712bf7c1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # WaterDrop changelog
2
2
 
3
+ ## 2.8.11 (2025-09-27)
4
+ - [Enhancement] Provide fast-track for middleware-less flows (20% faster) for single message, 5000x faster for batches.
5
+ - [Enhancement] Optimize middlewares application by around 20%.
6
+ - [Change] Remove Ruby `3.1` according to the EOL schedule.
7
+ - [Fix] Connection pool timeout parameter now accepts milliseconds instead of seconds for consistency with other WaterDrop timeouts. The default timeout has been changed from `5` seconds to `5000` milliseconds (equivalent value).
8
+
3
9
  ## 2.8.10 (2025-09-25)
4
10
  - [Enhancement] Add `#close` alias for `WaterDrop::ConnectionPool#shutdown` to align with producer API for consistent interface across both individual producers and connection pools.
5
11
  - [Enhancement] Add `WaterDrop.monitor` method as the preferred alias for `WaterDrop.instrumentation` to align with per-producer API naming convention. The `instrumentation` method remains available as a deprecated alias for backward compatibility.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- waterdrop (2.8.10)
4
+ waterdrop (2.8.11)
5
5
  karafka-core (>= 2.4.9, < 3.0.0)
6
6
  karafka-rdkafka (>= 0.20.0)
7
7
  zeitwerk (~> 2.3)
@@ -47,7 +47,7 @@ module WaterDrop
47
47
  # Sets up a global connection pool
48
48
  #
49
49
  # @param size [Integer] Pool size (default: 5)
50
- # @param timeout [Numeric] Connection timeout in seconds (default: 5)
50
+ # @param timeout [Numeric] Connection timeout in milliseconds (default: 5000)
51
51
  # @param producer_config [Proc] Block to configure each producer in the pool
52
52
  # @yield [config, index] Block to configure each producer in the pool, receives config and
53
53
  # pool index
@@ -66,7 +66,7 @@ module WaterDrop
66
66
  # 'transactional.id': "my-app-#{index}"
67
67
  # }
68
68
  # end
69
- def setup(size: 5, timeout: 5, &producer_config)
69
+ def setup(size: 5, timeout: 5000, &producer_config)
70
70
  ensure_connection_pool_gem!
71
71
 
72
72
  @default_pool = new(size: size, timeout: timeout, &producer_config)
@@ -194,18 +194,18 @@ module WaterDrop
194
194
  # Creates a new WaterDrop connection pool
195
195
  #
196
196
  # @param size [Integer] Pool size (default: 5)
197
- # @param timeout [Numeric] Connection timeout in seconds (default: 5)
197
+ # @param timeout [Numeric] Connection timeout in milliseconds (default: 5000)
198
198
  # @param producer_config [Proc] Block to configure each producer in the pool
199
199
  # @yield [config, index] Block to configure each producer in the pool, receives config and
200
200
  # pool index
201
- def initialize(size: 5, timeout: 5, &producer_config)
201
+ def initialize(size: 5, timeout: 5000, &producer_config)
202
202
  self.class.send(:ensure_connection_pool_gem!)
203
203
 
204
204
  @producer_config = producer_config
205
205
  @pool_index = 0
206
206
  @pool_mutex = Mutex.new
207
207
 
208
- @pool = ::ConnectionPool.new(size: size, timeout: timeout) do
208
+ @pool = ::ConnectionPool.new(size: size, timeout: timeout / 1000.0) do
209
209
  producer_index = @pool_mutex.synchronize { @pool_index += 1 }
210
210
 
211
211
  WaterDrop::Producer.new do |config|
@@ -6,6 +6,7 @@ module WaterDrop
6
6
  def initialize
7
7
  @mutex = Mutex.new
8
8
  @steps = []
9
+ @count = 0
9
10
  end
10
11
 
11
12
  # Runs middleware on a single message prior to validation
@@ -16,6 +17,8 @@ module WaterDrop
16
17
  # @note You need to decide yourself whether you don't use the message hash data anywhere else
17
18
  # and you want to save on memory by modifying it in place or do you want to do a deep copy
18
19
  def run(message)
20
+ return message if @count.zero?
21
+
19
22
  @steps.each do |step|
20
23
  message = step.call(message)
21
24
  end
@@ -24,10 +27,18 @@ module WaterDrop
24
27
  end
25
28
 
26
29
  # @param messages [Array<Hash>] messages on which we want to run middlewares
27
- # @return [Array<Hash>] transformed messages
30
+ # @return [Array<Hash>] transformed messages or same messages if no transformation
28
31
  def run_many(messages)
29
- messages.map do |message|
30
- run(message)
32
+ # Skip middleware processing entirely if no middleware steps are configured
33
+ return messages if @count.zero?
34
+
35
+ # Use each_with_object to avoid creating intermediate arrays for large batches
36
+ messages.each_with_object([]) do |message, result|
37
+ @steps.each do |step|
38
+ message = step.call(message)
39
+ end
40
+
41
+ result << message
31
42
  end
32
43
  end
33
44
 
@@ -36,6 +47,7 @@ module WaterDrop
36
47
  def prepend(step)
37
48
  @mutex.synchronize do
38
49
  @steps.prepend step
50
+ @count = @steps.size
39
51
  end
40
52
  end
41
53
 
@@ -44,6 +56,7 @@ module WaterDrop
44
56
  def append(step)
45
57
  @mutex.synchronize do
46
58
  @steps.append step
59
+ @count = @steps.size
47
60
  end
48
61
  end
49
62
  end
@@ -3,5 +3,5 @@
3
3
  # WaterDrop library
4
4
  module WaterDrop
5
5
  # Current WaterDrop version
6
- VERSION = '2.8.10'
6
+ VERSION = '2.8.11'
7
7
  end
data/waterdrop.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency 'karafka-rdkafka', '>= 0.20.0'
21
21
  spec.add_dependency 'zeitwerk', '~> 2.3'
22
22
 
23
- spec.required_ruby_version = '>= 3.1.0'
23
+ spec.required_ruby_version = '>= 3.2.0'
24
24
 
25
25
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
26
26
  spec.executables = []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waterdrop
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.10
4
+ version: 2.8.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -146,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
146
  requirements:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
- version: 3.1.0
149
+ version: 3.2.0
150
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  requirements:
152
152
  - - ">="