esse 0.4.0.rc1 → 0.4.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/esse/document.rb +13 -5
- data/lib/esse/errors.rb +13 -0
- data/lib/esse/import/bulk.rb +1 -3
- data/lib/esse/repository/documents.rb +24 -1
- data/lib/esse/version.rb +1 -1
- 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: 378f933ddf41a9d403121e9272b87814a01ee9e462eea5b9ad556d1ba593e46a
|
4
|
+
data.tar.gz: b3551d3361c380b750ca4e52c065d3372e6ec0c5762526f0f65894c097c79163
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f70d6495c34e176226a16e22da5e04b3ac74cce0d3469a3fa3ddf61c133a402d5577113839b0f4a52935cc71564be08930b529e25abb610c6bee1fcdadad77bb
|
7
|
+
data.tar.gz: 1cd02580736bb222d0a6e3e7a26fbdc17e925dafbc8cda97eb87fb911c85f1dac4c32543ffdde3418fade6a632722492147278f6c293184d42cae6ccc2a3ee28
|
data/lib/esse/document.rb
CHANGED
@@ -109,10 +109,10 @@ module Esse
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def inspect
|
112
|
-
attributes =
|
113
|
-
value = send(
|
112
|
+
attributes = {id: :id, routing: :routing, source: :memoized_source}.map do |attr_name, attr_src|
|
113
|
+
value = send(attr_src)
|
114
114
|
next unless value
|
115
|
-
"#{
|
115
|
+
"#{attr_name}: #{value.inspect}"
|
116
116
|
rescue
|
117
117
|
nil
|
118
118
|
end.compact.join(', ')
|
@@ -131,9 +131,17 @@ module Esse
|
|
131
131
|
end
|
132
132
|
|
133
133
|
def mutated_source
|
134
|
-
return
|
134
|
+
return memoized_source unless @__mutations__
|
135
135
|
|
136
|
-
@__mutated_source__ ||=
|
136
|
+
@__mutated_source__ ||= memoized_source.merge(@__mutations__)
|
137
|
+
end
|
138
|
+
|
139
|
+
protected
|
140
|
+
|
141
|
+
def memoized_source
|
142
|
+
return @__memoized_source__ if defined?(@__memoized_source__)
|
143
|
+
|
144
|
+
@__memoized_source__ = source || {}
|
137
145
|
end
|
138
146
|
end
|
139
147
|
end
|
data/lib/esse/errors.rb
CHANGED
@@ -15,6 +15,19 @@ module Esse
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
class BulkResponseError < ::Esse::Error
|
19
|
+
attr_reader :response
|
20
|
+
|
21
|
+
def initialize(response)
|
22
|
+
@response = response
|
23
|
+
super(response)
|
24
|
+
end
|
25
|
+
|
26
|
+
def items
|
27
|
+
response.fetch('items', []).select { |item| item.values.dig(0, 'error') }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
18
31
|
ES_TRANSPORT_ERRORS = {
|
19
32
|
'MultipleChoices' => 'MultipleChoicesError', # 300
|
20
33
|
'MovedPermanently' => 'MovedPermanentlyError', # 301
|
data/lib/esse/import/bulk.rb
CHANGED
@@ -49,9 +49,7 @@ module Esse
|
|
49
49
|
requests.each do |request|
|
50
50
|
next unless request.body?
|
51
51
|
resp = yield request
|
52
|
-
if resp&.[]('errors')
|
53
|
-
raise resp&.fetch('items', [])&.select { |item| item.values.first['error'] }&.join("\n")
|
54
|
-
end
|
52
|
+
raise Esse::Transport::BulkResponseError.new(resp) if resp&.[]('errors')
|
55
53
|
end
|
56
54
|
rescue Faraday::TimeoutError, Esse::Transport::RequestTimeoutError => e
|
57
55
|
retry_count += 1
|
@@ -10,8 +10,31 @@ module Esse
|
|
10
10
|
def update_documents_attribute(name, ids_or_doc_headers = [], kwargs = {})
|
11
11
|
batch = documents_for_lazy_attribute(name, ids_or_doc_headers)
|
12
12
|
return if batch.empty?
|
13
|
+
kwargs = kwargs.transform_keys(&:to_sym)
|
13
14
|
|
14
|
-
|
15
|
+
if kwargs.delete(:index_on_missing) { true }
|
16
|
+
begin
|
17
|
+
index.bulk(**kwargs, update: batch)
|
18
|
+
rescue Esse::Transport::BulkResponseError => ex
|
19
|
+
ids = ex.items.map { |item| item.dig('update', '_id') }.compact
|
20
|
+
raise ex if ids.empty?
|
21
|
+
|
22
|
+
each_serialized_batch(eager_load_lazy_attributes: false, preload_lazy_attributes: false, id: ids) do |entries|
|
23
|
+
entries.each do |entry|
|
24
|
+
partial_doc = batch.find { |doc| doc.eql?(entry, match_lazy_doc_header: true) }
|
25
|
+
next unless partial_doc
|
26
|
+
|
27
|
+
partial_doc.source.each do |attr_name, attr_value|
|
28
|
+
entry.mutate(attr_name) { attr_value }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
index.bulk(**kwargs, index: entries)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
else
|
36
|
+
index.bulk(**kwargs, update: batch)
|
37
|
+
end
|
15
38
|
end
|
16
39
|
|
17
40
|
def documents_for_lazy_attribute(name, ids_or_doc_headers)
|
data/lib/esse/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.0.
|
4
|
+
version: 0.4.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos G. Zimmermann
|
8
8
|
autorequire:
|
9
9
|
bindir: exec
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|