-
Bug
-
Resolution: Fixed
-
Major
-
2.5.5, 2.6.2, 2.7
-
MOODLE_25_STABLE, MOODLE_26_STABLE, MOODLE_27_STABLE
-
MOODLE_25_STABLE, MOODLE_26_STABLE
-
The upgrade_grade_item_fix_sortorder function is still much too slow, even after MDL-43946.
On one of our sites, it appears this will take at least several hours to finish (I didn't let it go, just guessing from what progress it made after 30 minutes...) all the while blocking much happening with grade items.
The problem appears to be that when courses have a large amount of grade items (in our case some with 4000 and more) the related rows are updated thousands of times; besides the O(N*N) time complexity there is a huge bloating of the table during the transaction which causes its own problems.
My patch moves this update loop for a given course to memory in PHP, then writes the updates back out when that course is finished. This results in only O(N) rows updated, and completes in a few seconds on a problematic dataset.