ranked-model icon indicating copy to clipboard operation
ranked-model copied to clipboard

Touch the model when reassigning

Open adamcooper opened this issue 11 years ago • 4 comments

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 avatar Oct 23 '14 18:10 adamcooper

@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 avatar Oct 23 '14 18:10 mixonic

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

adamcooper avatar Oct 23 '14 19:10 adamcooper

@mixonic - I was thinking along the lines of something like this: https://github.com/zozi/ranked-model/commit/62a743b8398e49a16ac46193a0155c0558bc4ba6

adamcooper avatar Oct 24 '14 04:10 adamcooper

@adamcooper looks great! Happy to merge if you can work up some tests.

mixonic avatar Oct 24 '14 12:10 mixonic

Closing this for now. Happy to look at it again if there's a need.

brendon avatar Jun 04 '24 08:06 brendon