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

Rebalancing events are not visible to the application #202

Closed tjvc closed 3 weeks ago

tjvc commented 1 month ago

We index a model with a row_order column in Elasticsearch, and use this field to sort query results. We re-index records by way of an after_commit callback on the model. ranked-model uses update_all when rebalancing ranks, which skips callbacks. For us, this means that the row_order in Elasticsearch can drift from that in the database.

I'm sure there are good reasons to skip callbacks when rebalancing ranks. I took a look at the gem source to see if there might be a way to hook into rebalancing events that we could use to trigger a re-index of all records when needed (as opposed to whenever a single row order changes, just in case a rebalancing has occurred), but couldn't see one. Do you have any suggestions or thoughts on our use case? I wondered if something like instrumenting the gem with ActiveSupport notifications might provide a light touch way of enabling users to listen for rebalancing events and react to them if needed.

brendon commented 1 month ago

Hi @tjvc, I'd be open to this. Would you be keen to put together a PR with some documentation and tests? :)

tjvc commented 1 month ago

Thanks @brendon! I'll see if I can put a PR together in the next couple of weeks for you to take a look at.

brendon commented 1 month ago

Sounds good! :D

tjvc commented 1 month ago

@brendon let me know what you think of #203 when you have a moment to take a look? Thanks! 🙇‍♂️

brendon commented 1 month ago

That's a really nice PR :) One tweak and we'll be GTG :)

tjvc commented 3 weeks ago

Addressed in #203 - thanks @brendon! 🙌

brendon commented 3 weeks ago

Thank you too! :D