Touch the model when reassigning
Hi,
We are looking at using this gem and it looks like a great fit. We would like to be able to tell what models have changed as a result of the rebalancing. This is because we store the ordering column in a search index and don't want to have to update the entire list when a rebalance occurs.
Would you take a patch upstream that included a config option touch_record_when_rebalancing?
Thanks, Adam
@adamcooper Howdy! Rebalancing spreads the records out across the entire integer space. It will touch every record. Maybe you mean rearranging?
https://github.com/mixonic/ranked-model/blob/master/lib/ranked-model/ranker.rb#L171
These are the smaller adjustments that avoid rebalancing when possible. You suggest that because update_all is used, we don't modify the updated_at, and you would like to have an option to do that?
@mixonic - Yes. Having an option to also update the updated_at during the update_all calls is exactly what I'm looking for.
I had my terminology mixed up with rearranging vs. rebalancing.
Hm.. I didn't realize the rebalance would update every record in the list. We currently have hooks that update our index from this model. Some lists have 4000 items and to re-index them takes ~10 mins. I guess I may need to override the rebalance_ranks method to disable the indexing and queue up a background job..
@mixonic - I was thinking along the lines of something like this: https://github.com/zozi/ranked-model/commit/62a743b8398e49a16ac46193a0155c0558bc4ba6
@adamcooper looks great! Happy to merge if you can work up some tests.
Closing this for now. Happy to look at it again if there's a need.