wal 0.0.13 → 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 +4 -4
- data/README.md +1 -1
- data/exe/wal +0 -5
- data/lib/wal/record_watcher.rb +24 -3
- data/lib/wal/version.rb +1 -1
- data/rbi/wal.rbi +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14c30e66cc9c1425cb894a9cfb558941017659cf4f0ad5a2183782c25df4a5b4
|
4
|
+
data.tar.gz: 7704871035cecbb90ee47cbefff50ad2fe58b4515f7d2c0d439e40adf31bf3f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e47256ec844eace9aabb20a1364fc0d0ab724e81c335f7b0bbb826871a328d8a0dca806d3e2ec891717339acc2286b2f71c2f424ccfed60c906772ded95f10ef
|
7
|
+
data.tar.gz: 0c584c14ec81977b7a26d66117a42180c73450da3a53ec9fa7dc5fe6ddd11e941833de45024032b3a8c7d31ddab6f7261911eaff7e2d83328031d7b8f4ddf9b2
|
data/README.md
CHANGED
data/exe/wal
CHANGED
@@ -45,11 +45,6 @@ if cli["watch"]
|
|
45
45
|
elsif cli["start"]
|
46
46
|
slots = YAML.load_file(cli["<config-file>"])["slots"]
|
47
47
|
|
48
|
-
if slots.size > 1 && slots.values.any? { |slot| slot["replicator"] == "Wal::Pro::Replicator" }
|
49
|
-
$stderr.puts "Error: wal-pro doesn't support multiple replication slots"
|
50
|
-
exit 1
|
51
|
-
end
|
52
|
-
|
53
48
|
workers = slots.map do |slot, config|
|
54
49
|
watcher = config["watcher"].constantize.new
|
55
50
|
temporary = config["temporary"] || false
|
data/lib/wal/record_watcher.rb
CHANGED
@@ -27,7 +27,7 @@ module Wal
|
|
27
27
|
# end
|
28
28
|
# end
|
29
29
|
#
|
30
|
-
#
|
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.
|
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
|
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
data/rbi/wal.rbi
CHANGED
@@ -7,7 +7,7 @@ module Wal
|
|
7
7
|
UpdateEvent,
|
8
8
|
DeleteEvent,
|
9
9
|
) }
|
10
|
-
VERSION = "0.0.
|
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.
|
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.
|
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-
|
10
|
+
date: 2025-09-16 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: pg
|