Skip to content

Commit

Permalink
Use pluck instead of map
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbyMcWho committed Jun 29, 2022
1 parent 6aee0b4 commit e3ea9fb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/searchkick/relation_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def resume_relation(relation)
end

def in_batches(relation)
if relation.respond_to?(:find_in_batches)
if relation.respond_to?(:in_batches)
klass = relation.klass
# remove order to prevent possible warnings
relation.except(:order).find_in_batches(batch_size: batch_size) do |batch|
relation.except(:order).in_batches(of: batch_size).each do |batch|
# prevent scope from affecting search_data as well as inline jobs
# Active Record runs relation calls in scoping block
# https://github.com/rails/rails/blob/main/activerecord/lib/active_record/relation/delegation.rb
Expand All @@ -77,12 +77,12 @@ def in_batches(relation)
if previous_scope
begin
klass.current_scope = nil
yield batch
yield batch.pluck(:id)
ensure
klass.current_scope = previous_scope
end
else
yield batch
yield batch.pluck(:id)
end
end
else
Expand All @@ -109,7 +109,7 @@ def each_batch(relation, batch_size:)
# https://github.com/karmi/tire/blob/master/lib/tire/model/import.rb
# use cursor for Mongoid
items = []
relation.all.each do |item|
relation.all.pluck(:_id).each do |item|
items << item
if items.length == batch_size
yield items
Expand Down

0 comments on commit e3ea9fb

Please sign in to comment.