From 82905c097ca064a90e41bbbae220e060862071ac Mon Sep 17 00:00:00 2001 From: Russell Smith Date: Wed, 14 Sep 2016 09:46:43 +1000 Subject: [PATCH] MDL-51584 gradebook: use direct $CFG access for freeze. get_config() is called a lot of times on freeze and is expensive, using $CFG is much lower overhead. --- lib/grade/grade_category.php | 16 +++++++++------- lib/grade/grade_grade.php | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 7ad1284ac60..96d8a2aac07 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -996,6 +996,8 @@ class grade_category extends grade_object { & $weights = null, $grademinoverrides = array(), $grademaxoverrides = array()) { + global $CFG; + $category_item = $this->load_grade_item(); $grademin = $category_item->grademin; $grademax = $category_item->grademax; @@ -1283,8 +1285,9 @@ class grade_category extends grade_object { // This setting indicates if we should use algorithm prior to MDL-49257 fix for calculating extra credit weights. // Even though old algorith has bugs in it, we need to preserve existing grades. - $gradebookcalculationfreeze = (int)get_config('core', 'gradebook_calculations_freeze_' . $this->courseid); - $oldextracreditcalculation = $gradebookcalculationfreeze && ($gradebookcalculationfreeze <= 20150619); + $gradebookcalculationfreeze = 'gradebook_calculations_freeze_' . $this->courseid; + $oldextracreditcalculation = isset($CFG->$gradebookcalculationfreeze) + && ($CFG->$gradebookcalculationfreeze <= 20150619); $sumweights = 0; $grademin = 0; @@ -1479,7 +1482,7 @@ class grade_category extends grade_object { * @return void */ private function auto_update_max() { - global $DB; + global $CFG, $DB; if ($this->aggregation != GRADE_AGGREGATE_SUM) { // not needed at all return; @@ -1491,11 +1494,10 @@ class grade_category extends grade_object { // Check to see if the gradebook is frozen. This allows grades to not be altered at all until a user verifies that they // wish to update the grades. - $gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $this->courseid); + $gradebookcalculationfreeze = 'gradebook_calculations_freeze_' . $this->courseid; + $oldextracreditcalculation = isset($CFG->$gradebookcalculationfreeze) && ($CFG->$gradebookcalculationfreeze <= 20150627); // Only run if the gradebook isn't frozen. - if ($gradebookcalculationsfreeze && (int)$gradebookcalculationsfreeze <= 20150627) { - // Do nothing. - } else{ + if (!$oldextracreditcalculation) { // Don't automatically update the max for calculated items. if ($this->grade_item->is_calculated()) { return; diff --git a/lib/grade/grade_grade.php b/lib/grade/grade_grade.php index d258820e408..eb57b0dd7eb 100644 --- a/lib/grade/grade_grade.php +++ b/lib/grade/grade_grade.php @@ -352,9 +352,9 @@ class grade_grade extends grade_object { // Check to see if the gradebook is frozen. This allows grades to not be altered at all until a user verifies that they // wish to update the grades. - $gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $this->grade_item->courseid); + $gradebookcalculationsfreeze = 'gradebook_calculations_freeze_' . $this->grade_item->courseid; // Gradebook is frozen, run through old code. - if ($gradebookcalculationsfreeze && (int)$gradebookcalculationsfreeze <= 20150627) { + if (isset($CFG->$gradebookcalculationsfreeze) && (int)$CFG->$gradebookcalculationsfreeze <= 20150627) { // Only aggregate items use separate min grades. if ($minmaxtouse == GRADE_MIN_MAX_FROM_GRADE_GRADE || $this->grade_item->is_aggregate_item()) { return array($this->rawgrademin, $this->rawgrademax);