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.
This commit is contained in:
Adam Olley
2014-08-06 15:58:11 +09:30
parent 6b7a5f86a0
commit a175c5d1ba
+4 -2
View File
@@ -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++;