-
-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Customize spread to maintain bigger emptiness in the rank ends. #195
Conversation
Co-authored-by: Frysch <anders.fryksborn@gmail.com> Co-authored-by: Caleb Buxton <caleb.buxton@babylist.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @cpb, this will be a good addition :) Just a few things to sort :)
modifier = min < max ? 1 : -1 | ||
|
||
if (max - min).abs < ranker.preferred_spread * 2 | ||
rank_at(min + (max - min).abs * 0.3 * modifier) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you walk me through the 0.3
? :)
@@ -229,11 +252,13 @@ def rebalance_ranks | |||
gaps = current_order.size + 1 | |||
range = (RankedModel::MAX_RANK_VALUE - RankedModel::MIN_RANK_VALUE).to_f | |||
gap_size = (range / gaps).ceil | |||
gap_size = ranker.preferred_spread if ranker.preferred_spread && gap_size > ranker.preferred_spread | |||
base_position = ranker.preferred_spread ? -gap_size * ((current_order.count + 1) / 2).ceil : RankedModel::MIN_RANK_VALUE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also a quick explainer of this would be helpful. I'm in a bit of a rush so it'd save me some figuring out time :D
@@ -170,12 +179,26 @@ def update_index_from_position | |||
end | |||
end | |||
|
|||
def possibly_rebalance_and_position(min, max) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be improved in terms of how it's used and reads :) I'll have a think.
@cpb, do you still want to progress this? I'll close it for now, but let me know if you do and I'll re-open it. |
Co-authored-by: Frysch anders.fryksborn@gmail.com
Co-authored-by: Caleb Buxton caleb.buxton@babylist.com
Rebases the preferred_spread Feature atop of the latest:
Requesting Clarification:
I've added test coverage that illustrates rebalancing during adds.
This is an opt-in feature, so there isn't impact on the cases the original implementation is optimized for … which is to say: very few additions, and quite a lot of reordering.
While the maximum integer available in MySQL is a rather large number, its
log2
isn't. The strategy provided by @frysch supports flexible allocation of the MySQL maximum integer space, so users can tune it to their use case.