before_update called even when no positioning columns are updated
creativetags opened this issue · 3 comments
I'm assuming this is not intended to happen but it appears that the before_update callback is issued even when the positioning column wouldn't be touched. It creates a lot of unnecessary calls to the db.
Hi @creativetags, the callback always runs because we need to determine within there if the position or scope (or both) have changed and then react. If a position is actually assigned from parameters (even if it's the same value) we force will_change
because it could be that the scope has changed and we coincidentally want to position the item in the new scope at the same position it was in in the old scope:
positioning/lib/positioning.rb
Line 42 in ead38ac
Here's the code where we determine if we need to shuffle anything:
positioning/lib/positioning/mechanisms.rb
Lines 22 to 39 in ead38ac
Can you let me know a scenario where nothing changes (including you not just including the current position
in your params) where any db calls are made?
Ok, I misunderstood. Thanks for explaining
That's all good. Glad it wasn't anything serious :)