wal 0.0.14 → 0.0.15

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: a10c111df779be284d3a1e20dac362c574d0abed4483d86479ad716c39c868dd
4
- data.tar.gz: 18763673175466a85adef9b3d91eb6a188bfc2db1b8cd178678757b81a912eb1
3
+ metadata.gz: 14c30e66cc9c1425cb894a9cfb558941017659cf4f0ad5a2183782c25df4a5b4
4
+ data.tar.gz: 7704871035cecbb90ee47cbefff50ad2fe58b4515f7d2c0d439e40adf31bf3f4
5
5
  SHA512:
6
- metadata.gz: 762f7c704d2a0dceafd9c1094e1413dbe272b7c71d676a49bcbc652d0d5266e91de357f8dd44cd5b4e26b8ec0ba2bde628c997b83cb64e1df9a218164d1ec686
7
- data.tar.gz: ed456c724a0d80a36f7d78bd477a059d89142f68f85293ff9225eb8ad4cc9a1fc3900781cf888c36742bb4406161542d9935fef9e6e3dd3919d4da51fe4f390c
6
+ metadata.gz: e47256ec844eace9aabb20a1364fc0d0ab724e81c335f7b0bbb826871a328d8a0dca806d3e2ec891717339acc2286b2f71c2f424ccfed60c906772ded95f10ef
7
+ data.tar.gz: 0c584c14ec81977b7a26d66117a42180c73450da3a53ec9fa7dc5fe6ddd11e941833de45024032b3a8c7d31ddab6f7261911eaff7e2d83328031d7b8f4ddf9b2
data/README.md CHANGED
@@ -14,7 +14,7 @@ class ProductAvailabilityWatcher < Wal::RecordWatcher
14
14
  recalculate_inventory_price(event.primary_key, event.new["price"])
15
15
  end
16
16
 
17
- on_destroy Product do |event|
17
+ on_delete Product do |event|
18
18
  clear_product_inventory(event.primary_key)
19
19
  end
20
20
 
@@ -27,7 +27,7 @@ module Wal
27
27
  # end
28
28
  # end
29
29
  #
30
- # on_destroy OrderItem do |event|
30
+ # on_delete OrderItem do |event|
31
31
  # recalculate_inventory_availability(event.attribute(:item_id))
32
32
  # end
33
33
  #
@@ -60,7 +60,7 @@ module Wal
60
60
  @@change_callbacks[table].push(only: [:create, :update], changed: changed&.map(&:to_s), block: block)
61
61
  end
62
62
 
63
- def self.on_destroy(table, &block)
63
+ def self.on_delete(table, &block)
64
64
  table = table.is_a?(String) ? table : table.table_name
65
65
  @@delete_callbacks[table].push(block: block)
66
66
  end
@@ -102,7 +102,7 @@ module Wal
102
102
  (@@change_callbacks.keys | @@delete_callbacks.keys).include? table
103
103
  end
104
104
 
105
- # `RecordWatcher` supports two processing strategies:
105
+ # `RecordWatcher` supports three processing strategies:
106
106
  #
107
107
  # `:memory`: Stores and aggregates records from a single transaction in memory. This has better performance but uses
108
108
  # more memory, as at least one event for each record must be stored in memory until the end of a transaction
@@ -110,6 +110,10 @@ module Wal
110
110
  # `:temporary_table`: Offloads the record aggregation to a temporary table on the database. This is useful when you
111
111
  # are processing very large transactions that can't fit in memory. The tradeoff is obviously a worse performance.
112
112
  #
113
+ # `:none`: Doesn't aggregate anything at all, so multiple updates on the same record on the same transaction would
114
+ # be notified. Also, if the same record is deleted on the same transaction it was created, this would end up
115
+ # triggering both `on_insert` and `on_delete` callbacks. This strategy should usually be avoided.
116
+ #
113
117
  # These strategies can be defined per transaction, and by default it will uses the memory one, and only fallback
114
118
  # to the temporary table if the transaction size is roughly 2 gigabytes or more.
115
119
  def aggregation_strategy(begin_transaction_event)
@@ -127,6 +131,8 @@ module Wal
127
131
  MemoryRecordWatcher.new(self)
128
132
  when :temporary_table
129
133
  TemporaryTableRecordWatcher.new(self)
134
+ when :none
135
+ NoAggregationWatcher.new(self)
130
136
  else
131
137
  raise "Invalid aggregation strategy: #{strategy}"
132
138
  end
@@ -134,6 +140,21 @@ module Wal
134
140
  @current_record_watcher.on_event(event)
135
141
  end
136
142
 
143
+ class NoAggregationWatcher
144
+ include Wal::Watcher
145
+
146
+ def initialize(watcher)
147
+ @watcher = watcher
148
+ end
149
+
150
+ def on_event(event)
151
+ case event
152
+ when InsertEvent, UpdateEvent, DeleteEvent
153
+ @watcher.on_record_changed(event)
154
+ end
155
+ end
156
+ end
157
+
137
158
  class MemoryRecordWatcher
138
159
  include Wal::Watcher
139
160
  include Wal::Watcher::SeparatedEvents
data/lib/wal/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wal
4
- VERSION = "0.0.14"
4
+ VERSION = "0.0.15"
5
5
  end
data/rbi/wal.rbi CHANGED
@@ -7,7 +7,7 @@ module Wal
7
7
  UpdateEvent,
8
8
  DeleteEvent,
9
9
  ) }
10
- VERSION = "0.0.14"
10
+ VERSION = "0.0.15"
11
11
 
12
12
  class BeginTransactionEvent < T::Struct
13
13
  prop :transaction_id, Integer, immutable: true
@@ -128,7 +128,7 @@ module Wal
128
128
  def self.on_save(table, changed: nil, &block); end
129
129
 
130
130
  sig { params(table: T.any(String, T.class_of(::ActiveRecord::Base)), block: T.proc.bind(T.attached_class).params(event: Wal::DeleteEvent).void).void }
131
- def self.on_destroy(table, &block); end
131
+ def self.on_delete(table, &block); end
132
132
 
133
133
  sig { params(event: RecordEvent).void }
134
134
  def on_record_changed(event); end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Navarro
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-09-14 00:00:00.000000000 Z
10
+ date: 2025-09-16 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: pg