dynamini 1.9.1 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/dynamini.gemspec +1 -1
- data/lib/dynamini/batch_operations.rb +10 -7
- data/lib/dynamini/test_client.rb +2 -1
- data/spec/dynamini/batch_operations_spec.rb +32 -12
- data/spec/dynamini/test_client_spec.rb +17 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b81e47262cde9752334d99b56bbc0b06d7ad3b2
|
4
|
+
data.tar.gz: 3026a65ee631076b6785012b4cbcebc4aa1c07cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03425cecdc1791ee2bb432b418275cd28af320275c6d7ed1a9bc60d4330989ea3fcf894aad2cef706698cf10487c1ac0ff20fde7466ba6227dbdb93903cd2ed7
|
7
|
+
data.tar.gz: 1826bf61ccb602299e4a1d8a9b426384bef196a3d238b8b86f7f4301a501c89934846408d418f153b260e6486fb7e9dea5d5dd374238c23e3c5de9346d95406f
|
data/Gemfile.lock
CHANGED
data/dynamini.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
1
3
|
module Dynamini
|
2
4
|
module BatchOperations
|
3
5
|
|
@@ -13,15 +15,16 @@ module Dynamini
|
|
13
15
|
end
|
14
16
|
|
15
17
|
def batch_find(ids = [])
|
16
|
-
return [] if ids.length < 1
|
18
|
+
return OpenStruct.new(found: [], not_found: []) if ids.length < 1
|
17
19
|
objects = []
|
18
|
-
|
19
|
-
key_structure
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
key_structure = ids.map { |i| {hash_key => i} }
|
21
|
+
key_structure.each_slice(100) do |keys|
|
22
|
+
response = dynamo_batch_get(keys)
|
23
|
+
response.responses[table_name].each do |item|
|
24
|
+
objects << new(item.symbolize_keys, false)
|
25
|
+
end
|
23
26
|
end
|
24
|
-
objects
|
27
|
+
OpenStruct.new(found: objects, not_found: ids - objects.map(&hash_key))
|
25
28
|
end
|
26
29
|
|
27
30
|
def dynamo_batch_save(model_array)
|
data/lib/dynamini/test_client.rb
CHANGED
@@ -61,6 +61,7 @@ module Dynamini
|
|
61
61
|
OpenStruct.new(item: attributes_hash)
|
62
62
|
end
|
63
63
|
|
64
|
+
#FIXME Add range key support
|
64
65
|
def batch_get_item(args = {})
|
65
66
|
responses = {}
|
66
67
|
|
@@ -68,7 +69,7 @@ module Dynamini
|
|
68
69
|
responses[k] = []
|
69
70
|
v[:keys].each do |key_hash|
|
70
71
|
item = @data[k][key_hash.values.first]
|
71
|
-
responses[k] << item
|
72
|
+
responses[k] << item unless item.nil?
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
@@ -52,23 +52,43 @@ describe Dynamini::BatchOperations do
|
|
52
52
|
end
|
53
53
|
context 'when requesting 0 items' do
|
54
54
|
it 'should return an empty array' do
|
55
|
-
expect(Dynamini::Base.batch_find).to eq []
|
55
|
+
expect(Dynamini::Base.batch_find.found).to eq []
|
56
|
+
expect(Dynamini::Base.batch_find.not_found).to eq []
|
56
57
|
end
|
57
58
|
end
|
58
|
-
|
59
|
-
|
59
|
+
|
60
|
+
context 'when requesting multiple items' do
|
61
|
+
let(:result) { Dynamini::Base.batch_find(%w(abcd1234 4321 foo)) }
|
62
|
+
before do
|
60
63
|
Dynamini::Base.create(id: '4321')
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
expect(
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should return the found items' do
|
67
|
+
expect(result.found.length).to eq 2
|
68
|
+
expect(result.found.first.id).to eq model.id
|
69
|
+
expect(result.found.last.id).to eq '4321'
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should return the hash keys of the items not found' do
|
73
|
+
expect(result.not_found).to eq(['foo'])
|
65
74
|
end
|
66
75
|
end
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
76
|
+
|
77
|
+
context 'when requesting over 100 items' do
|
78
|
+
let(:ids) { Array.new(50, 'foo') + Array.new(51, '4321')}
|
79
|
+
before do
|
80
|
+
Dynamini::Base.create(id: '4321')
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should call dynamo once for each 100 items' do
|
84
|
+
expect(Dynamini::Base).to receive(:dynamo_batch_get).twice.and_call_original
|
85
|
+
Dynamini::Base.batch_find(ids)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should return the combined responses of multiple dynamo calls' do
|
89
|
+
result = Dynamini::Base.batch_find(ids)
|
90
|
+
expect(result.found.length).to eq(51)
|
91
|
+
expect(result.not_found.length).to eq(50)
|
72
92
|
end
|
73
93
|
end
|
74
94
|
end
|
@@ -184,4 +184,21 @@ describe Dynamini::TestClient do
|
|
184
184
|
expect(test_client.data[table_name][2]).to eq(item2)
|
185
185
|
end
|
186
186
|
end
|
187
|
+
|
188
|
+
describe '#batch_get_item' do
|
189
|
+
let(:test_client) { Dynamini::TestClient.new(:id) }
|
190
|
+
|
191
|
+
before do
|
192
|
+
test_client.data[table_name] = {}
|
193
|
+
test_client.data[table_name]['foo'] = {id: 'foo', price: 1}
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'should only return the items found' do
|
197
|
+
keys = [{id: 'foo'}, {id: 'bar'}]
|
198
|
+
request = {request_items: {table_name => {keys: keys}}}
|
199
|
+
result = test_client.batch_get_item(request)
|
200
|
+
expect(result.responses[table_name].length).to eq(1)
|
201
|
+
expect(result.responses[table_name].first[:id]).to eq('foo')
|
202
|
+
end
|
203
|
+
end
|
187
204
|
end
|