Skip to content

Commit

Permalink
feat: esse-async_indexing use the #each_batch_ids collection method
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Jul 18, 2024
1 parent f41f9ab commit a70d4fe
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ gem 'sqlite3', '~> 1.7.3'
gem 'activerecord', '~> 5.2'
gem 'esse-rspec', '~> 0.0.6'
gem 'elasticsearch', '~> 7.17', '>= 7.17.10'
gem 'esse-redis-storage', '~> 0.0.1'

# Specify your gem's dependencies in esse-active_record.gemspec
gemspec
9 changes: 0 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ GEM
base64 (0.2.0)
coderay (1.1.3)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
crack (0.4.5)
rexml
diff-lcs (1.5.0)
Expand All @@ -43,9 +42,6 @@ GEM
esse (0.3.1)
multi_json
thor (>= 0.19)
esse-redis-storage (0.0.1)
esse (>= 0.2.4)
redis (>= 4.0.0)
esse-rspec (0.0.6)
esse (>= 0.2.4)
rspec (>= 3)
Expand Down Expand Up @@ -75,10 +71,6 @@ GEM
racc (1.7.3)
rainbow (3.1.1)
rake (13.1.0)
redis (5.2.0)
redis-client (>= 0.22.0)
redis-client (0.22.2)
connection_pool
regexp_parser (2.9.0)
rexml (3.2.6)
rspec (3.12.0)
Expand Down Expand Up @@ -152,7 +144,6 @@ DEPENDENCIES
elasticsearch (~> 7.17, >= 7.17.10)
esse (~> 0.3.1)
esse-active_record!
esse-redis-storage (~> 0.0.1)
esse-rspec (~> 0.0.6)
pry
rake
Expand Down
2 changes: 1 addition & 1 deletion lib/esse/active_record/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def each
end
end

def ids_in_batches
def each_batch_ids
dataset.select(:id).except(:includes, :preload).find_in_batches(**batch_options) do |rows|
yield(rows.map(&:id))
end
Expand Down
12 changes: 6 additions & 6 deletions spec/esse/active_record/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,18 @@
end
end

describe '#ids_in_batches' do
describe '#each_batch_ids' do
it 'raises NotImplementedError when scope is not defined on the collection class' do
expect {
collection = described_class.new
collection.ids_in_batches
collection.each_batch_ids
}.to raise_error(NotImplementedError)
end

it 'returns an Enumerator with a relation instance' do
collection = Class.new(described_class)
collection.base_scope = -> { Animal.all }
expect { |b| collection.new.ids_in_batches(&b) }.not_to yield_control
expect { |b| collection.new.each_batch_ids(&b) }.not_to yield_control
end

context 'with start and batch_size' do
Expand All @@ -129,19 +129,19 @@
it 'stream entity ids in batches according to the :batch_size option' do
instance = collection_class.new(batch_size: 1)

expect { |b| instance.ids_in_batches(&b) }.to yield_successive_args(*dogs.map { |doc| [doc.id] })
expect { |b| instance.each_batch_ids(&b) }.to yield_successive_args(*dogs.map { |doc| [doc.id] })
end

it 'stream entity ids in batches according to the :batch_size option and :start option' do
instance = collection_class.new(batch_size: 1, start: dogs[1].id)

expect { |b| instance.ids_in_batches(&b) }.to yield_successive_args(*dogs[1..2].map { |doc| [doc.id] })
expect { |b| instance.each_batch_ids(&b) }.to yield_successive_args(*dogs[1..2].map { |doc| [doc.id] })
end

it 'stream entity ids in batches according to the :batch_size option and :finish option' do
instance = collection_class.new(batch_size: 1, finish: dogs[1].id)

expect { |b| instance.ids_in_batches(&b) }.to yield_successive_args(*dogs[0..1].map { |doc| [doc.id] })
expect { |b| instance.each_batch_ids(&b) }.to yield_successive_args(*dogs[0..1].map { |doc| [doc.id] })
end
end
end
Expand Down

0 comments on commit a70d4fe

Please sign in to comment.