Skip to content

Commit 8508577

Browse files
lompykarmi
authored andcommitted
[MODEL] Refactored the code in __find_in_batches to use Enumerable#each_slice
Closes elastic#378
1 parent 2b338c1 commit 8508577

File tree

1 file changed

+2
-12
lines changed
  • elasticsearch-model/lib/elasticsearch/model/adapters

1 file changed

+2
-12
lines changed

elasticsearch-model/lib/elasticsearch/model/adapters/mongoid.rb

+2-12
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,8 @@ module Importing
6464
#
6565
def __find_in_batches(options={}, &block)
6666
options[:batch_size] ||= 1_000
67-
items = []
68-
69-
all.no_timeout.each do |item|
70-
items << item
71-
72-
if items.length % options[:batch_size] == 0
73-
yield items
74-
items = []
75-
end
76-
end
77-
78-
unless items.empty?
67+
68+
all.no_timeout.each_slice(options[:batch_size]) do |items|
7969
yield items
8070
end
8171
end

0 commit comments

Comments
 (0)