brendon / ranked-model

An acts_as_sortable/acts_as_list replacement built for Rails 4+
https://github.com/mixonic/ranked-model
MIT License
1.09k stars 134 forks source link

Feature: Customize spread to maintain bigger emptiness in the rank ends. #195

Closed cpb closed 3 months ago

cpb commented 1 year ago

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'm still totally keen to solve this problem. Equal spacing really doesn't work when things are always appended to the end of the list. It's an exponential problem by the looks. The list can only be folded so many times before running out of accuracy. I still like the idea of using some kind of sub-spacing per my message above, but I get a gut feeling this might also suffer from the same problem eventually but it certainly won't cause problems with appending where list items don't often get shuffled.

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.

brendon commented 3 months ago

@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.