From 974053b93f9d64ff45aa0a3d02de07b42bd6139f Mon Sep 17 00:00:00 2001 From: David Monllao Date: Wed, 16 Sep 2015 13:32:29 +0800 Subject: [PATCH] MDL-48881 mod_lesson: A couple of performance improvements - Improve memory usage on db drivers not able to use recordsets properly - !array_key_exists replaced by empty calls --- mod/lesson/report.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mod/lesson/report.php b/mod/lesson/report.php index 0055996f972..4f4a3b36b0c 100644 --- a/mod/lesson/report.php +++ b/mod/lesson/report.php @@ -159,10 +159,6 @@ if ($action === 'delete') { exit(); } - // We have attempts and students, let's prepare all the information. - $attempts = $DB->get_recordset('lesson_attempts', array('lessonid' => $lesson->id), 'timeseen'); - $branches = $DB->get_recordset('lesson_branch', array('lessonid' => $lesson->id), 'timeseen'); - if (! $grades = $DB->get_records('lesson_grades', array('lessonid' => $lesson->id), 'completed')) { $grades = array(); } @@ -181,12 +177,13 @@ if ($action === 'delete') { echo $OUTPUT->box($seeallgradeslink, 'allcoursegrades'); } + // Build an array for output. $studentdata = array(); - // build an array for output + $attempts = $DB->get_recordset('lesson_attempts', array('lessonid' => $lesson->id), 'timeseen'); foreach ($attempts as $attempt) { // if the user is not in the array or if the retry number is not in the sub array, add the data for that try. - if (!array_key_exists($attempt->userid, $studentdata) || !array_key_exists($attempt->retry, $studentdata[$attempt->userid])) { + if (empty($studentdata[$attempt->userid]) || empty($studentdata[$attempt->userid][$attempt->retry])) { // restore/setup defaults $n = 0; $timestart = 0; @@ -235,9 +232,11 @@ if ($action === 'delete') { } } $attempts->close(); + + $branches = $DB->get_recordset('lesson_branch', array('lessonid' => $lesson->id), 'timeseen'); foreach ($branches as $branch) { // If the user is not in the array or if the retry number is not in the sub array, add the data for that try. - if (!array_key_exists($branch->userid, $studentdata) || !array_key_exists($branch->retry, $studentdata[$branch->userid])) { + if (empty($studentdata[$branch->userid]) || empty($studentdata[$branch->userid][$branch->retry])) { // Restore/setup defaults. $n = 0; $timestart = 0; -- 2.11.4.GIT