nexia_event_store 0.8.4 → 0.9.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/event_store/snapshot.rb +41 -8
- data/lib/event_store/version.rb +1 -1
- data/spec/event_store/snapshot_spec.rb +30 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9fbf9cc725ea71887c8785e94aea019349c526e7
|
|
4
|
+
data.tar.gz: c6c54fb4151ef09e612788a4f081f8796670b292
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f2608989c009e27f5b4db3b333d4c5a9cb47b3614910b5d4b2a9c18d49635ae0a721c6389107a7c3f4769f5a51383e382cfcc47df5d2b6b1bc6333bdc4b8150e
|
|
7
|
+
data.tar.gz: 3015b833c0b2dbe224469200b993a523fb1b4e3ad79d1187b11f34a5e880033b9d07ac801a39ca628f4624fdd425481980588a347b0453c84f0954bfc208fa65
|
data/lib/event_store/snapshot.rb
CHANGED
|
@@ -29,14 +29,14 @@ module EventStore
|
|
|
29
29
|
event_id(snapshot_key(fully_qualified_name: fully_qualified_name, sub_key: sub_key))
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def count(logger=default_logger)
|
|
33
|
-
|
|
32
|
+
def count(logger = default_logger)
|
|
33
|
+
read_with_rebuild(logger).count
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def each(logger=default_logger)
|
|
37
37
|
logger.info { "#{self.class.name}#each for #{@aggregate.id}" }
|
|
38
38
|
t = Time.now
|
|
39
|
-
events_hash =
|
|
39
|
+
events_hash = read_with_rebuild(logger)
|
|
40
40
|
logger.debug { "#{self.class.name}#auto_rebuild_snapshot took #{Time.now - t} seconds for #{@aggregate.id}" }
|
|
41
41
|
|
|
42
42
|
t = Time.now
|
|
@@ -90,19 +90,48 @@ module EventStore
|
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
logger.debug("valid_snapshot_event_ids: #{valid_snapshot_event_ids.inspect}")
|
|
93
|
-
|
|
93
|
+
if valid_snapshot_event_ids.any?
|
|
94
94
|
logger.debug("there are valid_snapshot_event_ids, persisting to redis")
|
|
95
95
|
valid_snapshot_event_ids += [:current_event_id, valid_snapshot_event_ids.last.to_i]
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
@redis.hmset(snapshot_event_id_table, valid_snapshot_event_ids)
|
|
99
|
-
@redis.hmset(snapshot_table, valid_snapshot_events)
|
|
100
|
-
end
|
|
97
|
+
update_snapshot_tables(valid_snapshot_event_ids, valid_snapshot_events)
|
|
101
98
|
end
|
|
102
99
|
end
|
|
103
100
|
|
|
101
|
+
def update_fqns!(logger = default_logger)
|
|
102
|
+
updated_events = replace_fqns_in_snapshot_hash(read_with_rebuild(logger)) { |fqn| yield fqn }
|
|
103
|
+
updated_event_ids = replace_fqns_in_snapshot_hash(current_event_id_numbers) { |fqn|
|
|
104
|
+
fqn == 'current_event_id' ? fqn : (yield fqn)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
update_snapshot_tables(updated_event_ids, updated_events, replace: true)
|
|
108
|
+
end
|
|
109
|
+
|
|
104
110
|
private
|
|
105
111
|
|
|
112
|
+
def replace_fqns_in_snapshot_hash(snapshot_keyed_hash)
|
|
113
|
+
snapshot_keyed_hash.inject([]) { |memo, (snapshot_key, value)|
|
|
114
|
+
new_key = replace_fqn_in_snapshot_key(snapshot_key) { |fqn| yield fqn }
|
|
115
|
+
memo + [new_key, value]
|
|
116
|
+
}
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def replace_fqn_in_snapshot_key(key)
|
|
120
|
+
fqn, sub_key = key.split(EventStore::SNAPSHOT_KEY_DELIMITER)
|
|
121
|
+
new_fqn = (yield fqn) || fqn
|
|
122
|
+
[new_fqn, sub_key].compact.join(EventStore::SNAPSHOT_KEY_DELIMITER)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# params are flattened hashes, i.e., [key1, val1, key2, val2, ...]
|
|
126
|
+
def update_snapshot_tables(event_ids_array, events_array, replace: false)
|
|
127
|
+
@redis.multi do
|
|
128
|
+
@redis.del snapshot_event_id_table if replace
|
|
129
|
+
@redis.hmset(snapshot_event_id_table, event_ids_array)
|
|
130
|
+
@redis.del snapshot_table if replace
|
|
131
|
+
@redis.hmset(snapshot_table, events_array)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
106
135
|
def default_logger
|
|
107
136
|
Logger.new('/dev/null')
|
|
108
137
|
end
|
|
@@ -155,5 +184,9 @@ module EventStore
|
|
|
155
184
|
rebuild_snapshot!(logger)
|
|
156
185
|
events_hash = read_raw_snapshot(logger)
|
|
157
186
|
end
|
|
187
|
+
|
|
188
|
+
def read_with_rebuild(logger = default_logger)
|
|
189
|
+
auto_rebuild_snapshot(read_raw_snapshot(logger), logger)
|
|
190
|
+
end
|
|
158
191
|
end
|
|
159
192
|
end
|
data/lib/event_store/version.rb
CHANGED
|
@@ -36,6 +36,36 @@ module EventStore
|
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
describe "#update_fqns!" do
|
|
40
|
+
let(:original_events) { client.snapshot.to_a }
|
|
41
|
+
|
|
42
|
+
it "replaces fully qualified names in the snapshot with the value of a block" do
|
|
43
|
+
client.snapshot.update_fqns! { |fqn|
|
|
44
|
+
fqn =~ /^(e[0-9])/ ? fqn.upcase : fqn
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
expected_snapshot_events = original_events.map { |serialized_event| serialized_event.fully_qualified_name.upcase }
|
|
48
|
+
expect(client.snapshot.map(&:fully_qualified_name).to_set).to eq(expected_snapshot_events.to_set)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "does not affect the current event id" do
|
|
52
|
+
old_event_id = client.snapshot.event_id
|
|
53
|
+
|
|
54
|
+
client.snapshot.update_fqns! { |fqn| fqn.upcase }
|
|
55
|
+
|
|
56
|
+
new_event_id = client.snapshot.event_id
|
|
57
|
+
|
|
58
|
+
expect(new_event_id).to eq(old_event_id)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "doesn't affect the fully qualified name when the block returns nil" do
|
|
62
|
+
old_fqns = original_events.map(&:fully_qualified_name)
|
|
63
|
+
client.snapshot.update_fqns! { |_fqn| nil }
|
|
64
|
+
|
|
65
|
+
expect(client.snapshot.map(&:fully_qualified_name).to_set).to eq(old_fqns.to_set)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
39
69
|
it "rebuilds a snapshot after it is deleted" do
|
|
40
70
|
snapshot = client.snapshot
|
|
41
71
|
client.delete_snapshot!
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nexia_event_store
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Paul Saieg, John Colvin
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2016-
|
|
12
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -235,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
235
235
|
version: '0'
|
|
236
236
|
requirements: []
|
|
237
237
|
rubyforge_project:
|
|
238
|
-
rubygems_version: 2.4.
|
|
238
|
+
rubygems_version: 2.4.5.1
|
|
239
239
|
signing_key:
|
|
240
240
|
specification_version: 4
|
|
241
241
|
summary: Ruby implementation of an EventSource (A+ES) for the Nexia Ecosystem
|