From fdfa0d497f26a4b59feb596fa59879ed65427440 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Thu, 13 Dec 2018 12:13:23 +0800 Subject: [PATCH] MDL-63761 grade: Performance fix for regrading Don't use a separate variable to count the number of items in finalids. --- lib/gradelib.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/gradelib.php b/lib/gradelib.php index 9e37c4267ae..e87b15bd4e6 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -1112,7 +1112,7 @@ function grade_recover_history_grades($userid, $courseid) { * * @param int $courseid The course ID * @param int $userid If specified try to do a quick regrading of the grades of this user only - * @param object $updated_item Optional grade item to be marked for regrading + * @param object $updated_item Optional grade item to be marked for regrading. It is required if $userid is set. * @param \core\progress\base $progress If provided, will be used to update progress on this long operation. * @return bool true if ok, array of errors if problems found. Grade item id => error message */ @@ -1191,7 +1191,6 @@ function grade_regrade_final_grades($courseid, $userid=null, $updated_item=null, $failed = 0; while (count($finalids) < count($gids)) { // work until all grades are final or error found - $count = 0; foreach ($gids as $gid) { if (in_array($gid, $finalids)) { continue; // already final @@ -1265,7 +1264,6 @@ function grade_regrade_final_grades($courseid, $userid=null, $updated_item=null, } else { $grade_items[$gid]->needsupdate = 0; } - $count++; $finalids[] = $gid; $updatedids[] = $gid; @@ -1275,7 +1273,7 @@ function grade_regrade_final_grades($courseid, $userid=null, $updated_item=null, } } - if ($count == 0) { + if (count($finalids) == 0) { $failed++; } else { $failed = 0;