-
Notifications
You must be signed in to change notification settings - Fork 245
Description
We have an issue with Model.rebuild! beeing slow on a dataset with some 10000 records and 4000 root elements (no parent) in a postgres database.
We tracked that down to statements updating the sort order column for all root elements over and over again
(looks like once for every root element, so its ~4k updates of 4k records) and postgres is getting slower and
slower on that, probably because of table/index bloat or other issues.
The update is done through the reorder_with_parent_id in the PostgresSQLAdapter module in numeric_order_support.rb .
Suggested fix:
Most of these updates could be avoided if the (2nd) where clause would be amended by a check if the value in the order column changes with the update (postgres executes a real update with a copied record even if nothing changes in the record) as most of the writes are skipped then.
Would you be open to such a change? I could open a PR then.
Of course we are open to other solutions, but several hours for the rebuild! is not a nice behavior.
This went down to some three minutes with the change.