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

Concurrent updates

Open vitobotta opened this issue 8 years ago • 1 comments

Hi!

I'm currently using this gem in an app with "Tasks" where completed tasks can be moved to the top of the list when "reopened" by updating the row_order_position attribute with the :first value. This works great if, say, I manually reopen completed tasks one per time, however I also have schedules which automatically reopen certain tasks at some point in time, such as every day at midnight, and this happens asynchronously, meaning that it can easily happen that multiple tasks are moved to the top at the same time. This results in multiple tasks having the same rank/position in the list.

Do you know of any way I can avoid this and ensure each task has a unique rank even in the scenario I described? I tried things like locking and transactions with different isolation levels but with no luck (I'm using Postgres).

Thanks in advance!

vitobotta avatar Jun 26 '16 09:06 vitobotta

It may not solve your problem but per the idea in https://github.com/mixonic/ranked-model/issues/95, a unique index on the row_order column would prevent dups. Some kind of code to handle errors would be needed unless your async tasks can retry upon failure.

srt32 avatar Aug 23 '17 15:08 srt32