Commit 7c7a90da authored by Alexandru Croitor's avatar Alexandru Croitor

Move batch size to a constant

parent 5492f611
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
class IssueRebalancingService class IssueRebalancingService
MAX_ISSUE_COUNT = 10_000 MAX_ISSUE_COUNT = 10_000
BATCH_SIZE = 100
TooManyIssues = Class.new(StandardError) TooManyIssues = Class.new(StandardError)
def initialize(issue) def initialize(issue)
...@@ -21,13 +22,13 @@ class IssueRebalancingService ...@@ -21,13 +22,13 @@ class IssueRebalancingService
Issue.transaction do Issue.transaction do
assign_positions(start, indexed_ids) assign_positions(start, indexed_ids)
.sort_by(&:first) .sort_by(&:first)
.each_slice(100) do |pairs_with_position| .each_slice(BATCH_SIZE) do |pairs_with_position|
update_positions(pairs_with_position, 'rebalance issue positions in batches ordered by id') update_positions(pairs_with_position, 'rebalance issue positions in batches ordered by id')
end end
end end
else else
Issue.transaction do Issue.transaction do
indexed_ids.each_slice(100) do |pairs| indexed_ids.each_slice(BATCH_SIZE) do |pairs|
pairs_with_position = assign_positions(start, pairs) pairs_with_position = assign_positions(start, pairs)
update_positions(pairs_with_position, 'rebalance issue positions') update_positions(pairs_with_position, 'rebalance issue positions')
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment