praxis-mapper 4.0 → 4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -3
- data/lib/praxis-mapper/identity_map.rb +24 -15
- data/lib/praxis-mapper/version.rb +1 -1
- data/spec/praxis-mapper/identity_map_spec.rb +22 -1
- 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: 534dfb921f690285f07345acfe42725bdc8cef94
|
4
|
+
data.tar.gz: 603a6f23b61c9734595fc2358bc01f2d08de439f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09b91f6256a04bc776a3aabc82e1b070182c2a03ecdfd9d86edb5abcee01f06529d99f0bb5667a2fc202d5089370799f19f226f5e869ae676339802b385f1f88
|
7
|
+
data.tar.gz: 88dec0ce7600e96e87bc08963f8228c18e0b963ebbaa2da448a550e5287bc6331c330559d75d574b681052f5de4d67a5cb64f614b5067bb2e4b743e09f3d9357
|
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,22 @@
|
|
1
1
|
# praxis-mapper changelog
|
2
2
|
|
3
|
+
## next
|
4
|
+
|
5
|
+
## 4.1
|
6
|
+
|
7
|
+
* Added instrumentation through `ActiveSupport::Notifications`
|
8
|
+
* Use the 'praxis.mapper.load' to subscribe to `IdentityMap.load` calls
|
9
|
+
* Use the 'praxis.mapper.finalize' to subscribe to `IdentityMap.finalize!` calls
|
10
|
+
|
3
11
|
## 4.0
|
4
12
|
|
5
13
|
* Optimization on handling repeated ids (especially noticeable when using subloads)
|
6
14
|
* Refactored `ConnectionManager` repository handling to improve integration with other connection-pooling (specifically Sequel's at present).
|
7
15
|
* Added two types of connection factory under `Praxis::Mapper::ConnectionFactories::`:
|
8
16
|
* `Simple`: Takes a `connection:` option to specify the raw object to return for all `checkout`. Also, preserves current behavior with proc-based uses when `ConnectionManager.repository` is given a block. This is the default factory type if one is not specified for the repository.
|
9
|
-
* `Sequel`: Takes `connection:` option to specify a `Sequel::Database`, or hash of options to pass to `Sequel.connect`.
|
17
|
+
* `Sequel`: Takes `connection:` option to specify a `Sequel::Database`, or hash of options to pass to `Sequel.connect`.
|
10
18
|
* `IdentityMap#finalize!` now calls `ConnectionManager#release` to ensure any connections are returned to their respective pools, if applicable.
|
11
|
-
* Added `SequelCompat` module, which provides support for using `Sequel::Model` objects with an `IdentityMap` when included in model class.
|
19
|
+
* Added `SequelCompat` module, which provides support for using `Sequel::Model` objects with an `IdentityMap` when included in model class.
|
12
20
|
* This overrides the association accessors on instances associated with an `IdentityMap` (see below for more on this) to query the map instead of database.
|
13
21
|
* See (spec/support/spec_sequel_models.rb) for example definition.
|
14
22
|
* Added prototype for write-path support to `IdentityMap` (for `Sequel::Model` models):
|
@@ -18,7 +26,7 @@
|
|
18
26
|
* with no argument, or nil, given it saves all modified records in the identity map.
|
19
27
|
* with an instance of a model, it saves just that record.
|
20
28
|
* with a model class, it saves all modified records for that class in the identity map.
|
21
|
-
* `IdentityMap#remove`: calls `detatch` with the record, and then calls`record.delete` to delete it.
|
29
|
+
* `IdentityMap#remove`: calls `detatch` with the record, and then calls`record.delete` to delete it.
|
22
30
|
|
23
31
|
|
24
32
|
## 3.4.0
|
@@ -127,16 +127,18 @@ module Praxis::Mapper
|
|
127
127
|
return finalize_model!(model, query)
|
128
128
|
end
|
129
129
|
|
130
|
-
|
131
|
-
|
130
|
+
ActiveSupport::Notifications.instrument 'praxis.mapper.load', model: model do
|
131
|
+
records = query.execute
|
132
|
+
im_records = add_records(records)
|
132
133
|
|
133
|
-
|
134
|
-
|
135
|
-
|
134
|
+
# TODO: refactor this to better-hide queries?
|
135
|
+
query.freeze
|
136
|
+
queries[model].add(query)
|
136
137
|
|
137
|
-
|
138
|
+
subload(model, query, records)
|
138
139
|
|
139
|
-
|
140
|
+
im_records
|
141
|
+
end
|
140
142
|
end
|
141
143
|
|
142
144
|
def stage_for!(spec, records)
|
@@ -183,17 +185,25 @@ module Praxis::Mapper
|
|
183
185
|
end
|
184
186
|
end
|
185
187
|
|
186
|
-
def finalize!(*models)
|
187
|
-
if
|
188
|
-
|
188
|
+
def finalize!(*models, instrument: true)
|
189
|
+
if instrument
|
190
|
+
ActiveSupport::Notifications.instrument 'praxis.mapper.finalize' do
|
191
|
+
_finalize!(*models)
|
192
|
+
end
|
193
|
+
else
|
194
|
+
_finalize!(*models)
|
189
195
|
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def _finalize!(*models)
|
199
|
+
models = @staged.keys if models.empty?
|
190
200
|
|
191
201
|
did_something = models.any? do |model|
|
192
202
|
finalize_model!(model).any?
|
193
203
|
end
|
194
204
|
|
195
205
|
if did_something
|
196
|
-
|
206
|
+
_finalize!
|
197
207
|
else
|
198
208
|
release
|
199
209
|
end
|
@@ -205,19 +215,18 @@ module Praxis::Mapper
|
|
205
215
|
|
206
216
|
# don't doc. never ever use yourself!
|
207
217
|
# FIXME: make private and fix specs that break?
|
208
|
-
def finalize_model!(model, query=nil)
|
218
|
+
def finalize_model!(model, query = nil)
|
209
219
|
staged_queries = @staged[model].delete(:_queries) || []
|
210
220
|
staged_keys = @staged[model].keys
|
211
|
-
identities = staged_keys && model.identities
|
212
221
|
non_identities = staged_keys - model.identities
|
213
222
|
|
214
223
|
results = Set.new
|
215
224
|
|
216
|
-
return results if @staged[model].all? { |(
|
225
|
+
return results if @staged[model].all? { |(_key, values)| values.empty? }
|
217
226
|
|
218
227
|
if query.nil?
|
219
228
|
query_class = @connection_manager.repository(model.repository_name)[:query]
|
220
|
-
query = query_class.new(self,model)
|
229
|
+
query = query_class.new(self, model)
|
221
230
|
end
|
222
231
|
|
223
232
|
# Apply any relevant blocks passed to track in the original queries
|
@@ -104,6 +104,9 @@ describe Praxis::Mapper::IdentityMap do
|
|
104
104
|
it 'builds a query, executes, freezes it, and returns the query results' do
|
105
105
|
Praxis::Mapper::Support::MemoryQuery.any_instance.should_receive(:execute).and_return(records)
|
106
106
|
Praxis::Mapper::Support::MemoryQuery.any_instance.should_receive(:freeze)
|
107
|
+
ActiveSupport::Notifications.should_receive(:instrument).
|
108
|
+
with('praxis.mapper.load', {model: model}).
|
109
|
+
and_call_original
|
107
110
|
identity_map.load(model, &query_proc).should === records
|
108
111
|
end
|
109
112
|
|
@@ -141,7 +144,7 @@ describe Praxis::Mapper::IdentityMap do
|
|
141
144
|
identity_map.should_receive(:finalize_model!) do |model, query|
|
142
145
|
model.should be(AddressModel)
|
143
146
|
query.where.should be(nil)
|
144
|
-
query.track.should eq(Set.new([:foobar]))
|
147
|
+
query.track.should eq(Set.new([:foobar]))
|
145
148
|
end
|
146
149
|
end
|
147
150
|
end
|
@@ -283,7 +286,25 @@ describe Praxis::Mapper::IdentityMap do
|
|
283
286
|
end
|
284
287
|
end
|
285
288
|
|
289
|
+
context '#finalize!' do
|
290
|
+
let(:stage) { {:id => [1,2] } }
|
291
|
+
before do
|
292
|
+
identity_map.stage(PersonModel, stage)
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'sends the correct ActiveSupport::Notification' do
|
296
|
+
ActiveSupport::Notifications.should_receive(:instrument).
|
297
|
+
with('praxis.mapper.finalize').
|
298
|
+
and_call_original
|
299
|
+
identity_map.finalize!
|
300
|
+
end
|
286
301
|
|
302
|
+
it 'does not send ActiveSupport::Notification if instrument: false is passed' do
|
303
|
+
ActiveSupport::Notifications.should_not_receive(:instrument)
|
304
|
+
identity_map.finalize!(instrument: false)
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|
287
308
|
|
288
309
|
context "#finalize_model!" do
|
289
310
|
let(:record_query) { nil }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: praxis-mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '4.
|
4
|
+
version: '4.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josep M. Blanquer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-09-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: randexp
|
@@ -316,7 +316,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
316
316
|
version: '0'
|
317
317
|
requirements: []
|
318
318
|
rubyforge_project:
|
319
|
-
rubygems_version: 2.
|
319
|
+
rubygems_version: 2.4.5.1
|
320
320
|
signing_key:
|
321
321
|
specification_version: 4
|
322
322
|
summary: A multi-datastore library designed for efficiency in loading large datasets.
|