Commit f7696d50 authored by Alex Kalderimis's avatar Alex Kalderimis

Clearer computation of gap size

parent 4a226bf6
......@@ -23,12 +23,13 @@ class IssueRebalancingService
raise TooManyIssues, "#{n} issues"
end
range = RelativePositioning::MAX_POSITION - RelativePositioning::MIN_POSITION
gaps = n - 1
gap_size = 0
ratio = 0.5
while gap_size < RelativePositioning::MIN_GAP && ratio < 1
gap_size = (ratio * RelativePositioning::MAX_POSITION) / (gaps / 2)
gap_size = [RelativePositioning::IDEAL_DISTANCE, (ratio * range) / gaps].min.floor
ratio += 0.1
end
......@@ -37,7 +38,7 @@ class IssueRebalancingService
raise RelativePositioning::NoSpaceLeft
end
start = 0 - (gaps / 2) * gap_size
start = RelativePositioning::START_POSITION - (gaps / 2) * gap_size
Issue.transaction do
indexed = base.reorder(:relative_position, :id).pluck(:id).each_with_index
......
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