chewy 7.2.5 → 7.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +1 -0
- data/.github/workflows/ruby.yml +1 -1
- data/CHANGELOG.md +13 -1
- data/README.md +1 -0
- data/lib/chewy/fields/base.rb +1 -1
- data/lib/chewy/journal.rb +11 -4
- data/lib/chewy/search/parameters/collapse.rb +16 -0
- data/lib/chewy/search/request.rb +18 -7
- data/lib/chewy/version.rb +1 -1
- data/spec/chewy/fields/base_spec.rb +1 -0
- data/spec/chewy/journal_spec.rb +13 -49
- data/spec/chewy/search/parameters/collapse_spec.rb +5 -0
- data/spec/chewy/search/request_spec.rb +10 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96329a4913f6308f4c7435cd50b962a36dc63b728b50567ff53ce2cb8011086f
|
4
|
+
data.tar.gz: a25b93955769a85fdf5de68a6d284060a981c2e3f6e10c929b0cd49816c19720
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66a3dfa94536e8d7b262a6a0ccfe32ff76ca7431850722eef21b14a11b3d162ad0346c3a469293696ce79916c44db7fb17b56f462fd4083c619b2dde09fa6c29
|
7
|
+
data.tar.gz: 6e15e9fcb103c64a5565add1e5200caa4bf1018d3fc7e9ac79a8db6829a5bb1699ac77910e838d59df2f6f195d019a88c22987d51f1b02ebdbb8f37844cce8d3
|
data/.github/CODEOWNERS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.github/workflows @toptal/rogue-one
|
data/.github/workflows/ruby.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,17 @@
|
|
8
8
|
|
9
9
|
### Bugs Fixed
|
10
10
|
|
11
|
+
## 7.2.6 (2022-06-13)
|
12
|
+
|
13
|
+
### New Features
|
14
|
+
|
15
|
+
* [#841](https://github.com/toptal/chewy/pull/841): Add the [`collapse`](https://www.elastic.co/guide/en/elasticsearch/reference/current/collapse-search-results.html) option to the request. ([@jkostolansky][])
|
16
|
+
|
17
|
+
### Bugs Fixed
|
18
|
+
|
19
|
+
* [#842](https://github.com/toptal/chewy/issues/842): Fix `ignore_blank` handling. ([@rabotyaga][])
|
20
|
+
* [#848](https://github.com/toptal/chewy/issues/848): Fix invalid journal pagination. ([@konalegi][])
|
21
|
+
|
11
22
|
## 7.2.5 (2022-03-04)
|
12
23
|
|
13
24
|
### New Features
|
@@ -15,7 +26,7 @@
|
|
15
26
|
* [#827](https://github.com/toptal/chewy/pull/827): Add `:lazy_sidekiq` strategy, that defers not only importing but also `update_index` callback evaluation for created and updated objects. ([@sl4vr][])
|
16
27
|
* [#827](https://github.com/toptal/chewy/pull/827): Add `:atomic_no_refresh` strategy. Like `:atomic`, but `refresh=false` parameter is set. ([@barthez][])
|
17
28
|
* [#827](https://github.com/toptal/chewy/pull/827): Add `:no_refresh` chain call to `update_index` matcher to ensure import was called with `refresh=false`. ([@barthez][])
|
18
|
-
|
29
|
+
|
19
30
|
### Bugs Fixed
|
20
31
|
|
21
32
|
* [#835](https://github.com/toptal/chewy/pull/835): Support keyword arguments in named scopes. ([@milk1000cc][])
|
@@ -696,6 +707,7 @@
|
|
696
707
|
[@jimmybaker]: https://github.com/jimmybaker
|
697
708
|
[@jirikolarik]: https://github.com/jirikolarik
|
698
709
|
[@jirutka]: https://github.com/jirutka
|
710
|
+
[@jkostolansky]: https://github.com/jkostolansky
|
699
711
|
[@joeljunstrom]: https://github.com/joeljunstrom
|
700
712
|
[@jondavidford]: https://github.com/jondavidford
|
701
713
|
[@joonty]: https://github.com/joonty
|
data/README.md
CHANGED
@@ -694,6 +694,7 @@ UsersIndex.import User.where('rating > 100') # or import specified users scope
|
|
694
694
|
UsersIndex.import User.where('rating > 100').to_a # or import specified users array
|
695
695
|
UsersIndex.import [1, 2, 42] # pass even ids for import, it will be handled in the most effective way
|
696
696
|
UsersIndex.import User.where('rating > 100'), update_fields: [:email] # if update fields are specified - it will update their values only with the `update` bulk action
|
697
|
+
UsersIndex.import! # raises an exception in case of any import errors
|
697
698
|
|
698
699
|
UsersIndex.reset! # purges index and imports default data for all types
|
699
700
|
```
|
data/lib/chewy/fields/base.rb
CHANGED
data/lib/chewy/journal.rb
CHANGED
@@ -16,14 +16,17 @@ module Chewy
|
|
16
16
|
# specified indexes.
|
17
17
|
#
|
18
18
|
# @param since_time [Time, DateTime] timestamp from which changes will be applied
|
19
|
-
# @param
|
19
|
+
# @param fetch_limit [Int] amount of entries to be fetched on each cycle
|
20
20
|
# @return [Integer] the amount of journal entries found
|
21
|
-
def apply(since_time,
|
21
|
+
def apply(since_time, fetch_limit: 10, **import_options)
|
22
22
|
stage = 1
|
23
23
|
since_time -= 1
|
24
24
|
count = 0
|
25
|
-
|
26
|
-
|
25
|
+
|
26
|
+
total_count = entries(since_time, fetch_limit).total_count
|
27
|
+
|
28
|
+
while count < total_count
|
29
|
+
entries = entries(since_time, fetch_limit).to_a.presence or break
|
27
30
|
count += entries.size
|
28
31
|
groups = reference_groups(entries)
|
29
32
|
ActiveSupport::Notifications.instrument 'apply_journal.chewy', stage: stage, groups: groups
|
@@ -46,6 +49,10 @@ module Chewy
|
|
46
49
|
|
47
50
|
private
|
48
51
|
|
52
|
+
def entries(since_time, fetch_limit)
|
53
|
+
Chewy::Stash::Journal.entries(since_time, only: @only).order(:created_at).limit(fetch_limit)
|
54
|
+
end
|
55
|
+
|
49
56
|
def reference_groups(entries)
|
50
57
|
entries.group_by(&:index_name)
|
51
58
|
.transform_keys { |index_name| Chewy.derive_name(index_name) }
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'chewy/search/parameters/storage'
|
2
|
+
|
3
|
+
module Chewy
|
4
|
+
module Search
|
5
|
+
class Parameters
|
6
|
+
# Just a standard hash storage. Nothing to see here.
|
7
|
+
#
|
8
|
+
# @see Chewy::Search::Parameters::HashStorage
|
9
|
+
# @see Chewy::Search::Request#collapse
|
10
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/collapse-search-results.html
|
11
|
+
class Collapse < Storage
|
12
|
+
include HashStorage
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/chewy/search/request.rb
CHANGED
@@ -24,7 +24,7 @@ module Chewy
|
|
24
24
|
track_scores track_total_hits request_cache explain version profile
|
25
25
|
search_type preference limit offset terminate_after
|
26
26
|
timeout min_score source stored_fields search_after
|
27
|
-
load script_fields suggest aggs aggregations none
|
27
|
+
load script_fields suggest aggs aggregations collapse none
|
28
28
|
indices_boost rescore highlight total total_count
|
29
29
|
total_entries indices types delete_all count exists?
|
30
30
|
exist? find pluck scroll_batches scroll_hits
|
@@ -41,7 +41,7 @@ module Chewy
|
|
41
41
|
EXTRA_STORAGES = %i[aggs suggest].freeze
|
42
42
|
# An array of storage names that are changing the returned hist collection in any way.
|
43
43
|
WHERE_STORAGES = %i[
|
44
|
-
query filter post_filter none min_score rescore indices_boost
|
44
|
+
query filter post_filter none min_score rescore indices_boost collapse
|
45
45
|
].freeze
|
46
46
|
|
47
47
|
delegate :hits, :wrappers, :objects, :records, :documents,
|
@@ -509,7 +509,18 @@ module Chewy
|
|
509
509
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-index.html#multi-index
|
510
510
|
# @param value [true, false, nil]
|
511
511
|
# @return [Chewy::Search::Request]
|
512
|
-
|
512
|
+
#
|
513
|
+
# @!method collapse(value)
|
514
|
+
# Replaces the value of the `collapse` request part.
|
515
|
+
#
|
516
|
+
# @example
|
517
|
+
# PlacesIndex.collapse(field: :name)
|
518
|
+
# # => <PlacesIndex::Query {..., :body=>{:collapse=>{"field"=>:name}}}>
|
519
|
+
# @see Chewy::Search::Parameters::Collapse
|
520
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/collapse-search-results.html
|
521
|
+
# @param value [Hash]
|
522
|
+
# @return [Chewy::Search::Request]
|
523
|
+
%i[request_cache search_type preference timeout limit offset terminate_after min_score ignore_unavailable collapse].each do |name|
|
513
524
|
define_method name do |value|
|
514
525
|
modify(name) { replace!(value) }
|
515
526
|
end
|
@@ -800,8 +811,8 @@ module Chewy
|
|
800
811
|
# Returns a new scope containing only specified storages.
|
801
812
|
#
|
802
813
|
# @example
|
803
|
-
# PlacesIndex.limit(10).offset(10).order(:name).
|
804
|
-
# # => <PlacesIndex::Query {..., :body=>{:
|
814
|
+
# PlacesIndex.limit(10).offset(10).order(:name).only(:offset, :order)
|
815
|
+
# # => <PlacesIndex::Query {..., :body=>{:from=>10, :sort=>["name"]}}>
|
805
816
|
# @param values [Array<String, Symbol>]
|
806
817
|
# @return [Chewy::Search::Request] new scope
|
807
818
|
def only(*values)
|
@@ -811,8 +822,8 @@ module Chewy
|
|
811
822
|
# Returns a new scope containing all the storages except specified.
|
812
823
|
#
|
813
824
|
# @example
|
814
|
-
# PlacesIndex.limit(10).offset(10).order(:name).
|
815
|
-
# # => <PlacesIndex::Query {..., :body=>{:
|
825
|
+
# PlacesIndex.limit(10).offset(10).order(:name).except(:offset, :order)
|
826
|
+
# # => <PlacesIndex::Query {..., :body=>{:size=>10}}>
|
816
827
|
# @param values [Array<String, Symbol>]
|
817
828
|
# @return [Chewy::Search::Request] new scope
|
818
829
|
def except(*values)
|
data/lib/chewy/version.rb
CHANGED
data/spec/chewy/journal_spec.rb
CHANGED
@@ -199,59 +199,23 @@ describe Chewy::Journal do
|
|
199
199
|
end
|
200
200
|
end
|
201
201
|
|
202
|
-
context '
|
203
|
-
let(:time) { Time.now
|
204
|
-
before do
|
205
|
-
Timecop.freeze
|
206
|
-
Chewy.strategy(:urgent)
|
207
|
-
City.create!(id: 1)
|
208
|
-
end
|
209
|
-
|
210
|
-
after do
|
211
|
-
Chewy.strategy.pop
|
212
|
-
Timecop.return
|
213
|
-
end
|
214
|
-
|
215
|
-
specify 'journal was cleaned after the first call' do
|
216
|
-
expect(Chewy::Stash::Journal).to receive(:entries).exactly(2).and_call_original
|
217
|
-
expect(described_class.new.apply(time)).to eq(1)
|
218
|
-
end
|
219
|
-
|
220
|
-
context 'endless journal' do
|
221
|
-
let(:count_of_checks) { 10 } # default
|
222
|
-
let!(:journal_entries) do
|
223
|
-
record = Chewy::Stash::Journal.entries(time).first
|
224
|
-
Array.new(count_of_checks) do |i|
|
225
|
-
Chewy::Stash::Journal.new(
|
226
|
-
record.attributes.merge(
|
227
|
-
'created_at' => time.to_i + i,
|
228
|
-
'references' => [i.to_s]
|
229
|
-
)
|
230
|
-
)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
specify '10 retries by default' do
|
235
|
-
expect(Chewy::Stash::Journal)
|
236
|
-
.to receive(:entries).exactly(count_of_checks) { [journal_entries.shift].compact }
|
237
|
-
expect(described_class.new.apply(time)).to eq(10)
|
238
|
-
end
|
202
|
+
context 'when order is not preserved' do
|
203
|
+
let(:time) { Time.now }
|
239
204
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
205
|
+
it 'paginates properly through all items' do
|
206
|
+
Chewy.strategy(:urgent) do
|
207
|
+
Timecop.travel(time + 1.minute) { City.create!(id: 2) }
|
208
|
+
Timecop.travel(time + 3.minute) { City.create!(id: 4) }
|
209
|
+
Timecop.travel(time + 2.minute) { City.create!(id: 1) }
|
210
|
+
Timecop.travel(time + 4.minute) { City.create!(id: 3) }
|
244
211
|
end
|
245
212
|
|
246
|
-
|
247
|
-
|
213
|
+
CitiesIndex.purge!
|
214
|
+
expect(CitiesIndex.all.to_a.length).to eq 0
|
248
215
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
expect(described_class.new.apply(time, retries: retries)).to eq(5)
|
253
|
-
end
|
254
|
-
end
|
216
|
+
# Replay on specific index
|
217
|
+
expect(described_class.new(CitiesIndex).apply(time, fetch_limit: 2)).to eq(4)
|
218
|
+
expect(CitiesIndex.all.to_a.map(&:id).sort).to eq([1, 2, 3, 4])
|
255
219
|
end
|
256
220
|
end
|
257
221
|
end
|
@@ -314,6 +314,16 @@ describe Chewy::Search::Request do
|
|
314
314
|
end
|
315
315
|
end
|
316
316
|
|
317
|
+
describe '#collapse' do
|
318
|
+
specify { expect(subject.collapse(foo: {bar: 42}).render[:body]).to include(collapse: {'foo' => {bar: 42}}) }
|
319
|
+
specify do
|
320
|
+
expect(subject.collapse(foo: {bar: 42}).collapse(moo: {baz: 43}).render[:body])
|
321
|
+
.to include(collapse: {'moo' => {baz: 43}})
|
322
|
+
end
|
323
|
+
specify { expect(subject.collapse(foo: {bar: 42}).collapse(nil).render[:body]).to be_blank }
|
324
|
+
specify { expect { subject.collapse(foo: {bar: 42}) }.not_to change { subject.render } }
|
325
|
+
end
|
326
|
+
|
317
327
|
describe '#docvalue_fields' do
|
318
328
|
specify { expect(subject.docvalue_fields(:foo).render[:body]).to include(docvalue_fields: ['foo']) }
|
319
329
|
specify do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chewy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.2.
|
4
|
+
version: 7.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toptal, LLC
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-06-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: database_cleaner
|
@@ -222,6 +222,7 @@ executables: []
|
|
222
222
|
extensions: []
|
223
223
|
extra_rdoc_files: []
|
224
224
|
files:
|
225
|
+
- ".github/CODEOWNERS"
|
225
226
|
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
226
227
|
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
227
228
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
@@ -293,6 +294,7 @@ files:
|
|
293
294
|
- lib/chewy/search/parameters.rb
|
294
295
|
- lib/chewy/search/parameters/aggs.rb
|
295
296
|
- lib/chewy/search/parameters/allow_partial_search_results.rb
|
297
|
+
- lib/chewy/search/parameters/collapse.rb
|
296
298
|
- lib/chewy/search/parameters/concerns/bool_storage.rb
|
297
299
|
- lib/chewy/search/parameters/concerns/hash_storage.rb
|
298
300
|
- lib/chewy/search/parameters/concerns/integer_storage.rb
|
@@ -389,6 +391,7 @@ files:
|
|
389
391
|
- spec/chewy/search/pagination/kaminari_spec.rb
|
390
392
|
- spec/chewy/search/parameters/aggs_spec.rb
|
391
393
|
- spec/chewy/search/parameters/bool_storage_examples.rb
|
394
|
+
- spec/chewy/search/parameters/collapse_spec.rb
|
392
395
|
- spec/chewy/search/parameters/docvalue_fields_spec.rb
|
393
396
|
- spec/chewy/search/parameters/explain_spec.rb
|
394
397
|
- spec/chewy/search/parameters/filter_spec.rb
|
@@ -461,7 +464,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
461
464
|
- !ruby/object:Gem::Version
|
462
465
|
version: '0'
|
463
466
|
requirements: []
|
464
|
-
rubygems_version: 3.
|
467
|
+
rubygems_version: 3.2.29
|
465
468
|
signing_key:
|
466
469
|
specification_version: 4
|
467
470
|
summary: Elasticsearch ODM client wrapper
|
@@ -505,6 +508,7 @@ test_files:
|
|
505
508
|
- spec/chewy/search/pagination/kaminari_spec.rb
|
506
509
|
- spec/chewy/search/parameters/aggs_spec.rb
|
507
510
|
- spec/chewy/search/parameters/bool_storage_examples.rb
|
511
|
+
- spec/chewy/search/parameters/collapse_spec.rb
|
508
512
|
- spec/chewy/search/parameters/docvalue_fields_spec.rb
|
509
513
|
- spec/chewy/search/parameters/explain_spec.rb
|
510
514
|
- spec/chewy/search/parameters/filter_spec.rb
|