From a175c5d1bad1c08c19ee1465a4ee438d1659fa02 Mon Sep 17 00:00:00 2001 From: Adam Olley Date: Wed, 6 Aug 2014 15:58:08 +0930 Subject: [PATCH] MDL-46697 gradebook: Only count active users when needed (and only id) The code only needs the id column to perform its count. On courses with a lot of users fetching the whole user record for them all easily adds up to several hundred MB of memory. --- grade/report/lib.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/grade/report/lib.php b/grade/report/lib.php index 3e757cd1084..082555f92e1 100644 --- a/grade/report/lib.php +++ b/grade/report/lib.php @@ -336,12 +336,14 @@ abstract class grade_report { if (!empty($selectedusers)) { $coursecontext = $this->context->get_course_context(true); - $useractiveenrolments = get_enrolled_users($coursecontext, '', 0, 'u.*', null, 0, 0, true); - $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol); $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol); $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $coursecontext); + if ($showonlyactiveenrol) { + $useractiveenrolments = get_enrolled_users($coursecontext, '', 0, 'u.id', null, 0, 0, true); + } + foreach ($selectedusers as $id => $value) { if (!$showonlyactiveenrol || ($showonlyactiveenrol && array_key_exists($id, $useractiveenrolments))) { $count++;