MDL-71838 quiz reports: average rows calc can run out of memory

Should not use get_records when you mean record_exists.
This commit is contained in:
Tim Hunt 2021-06-02 16:06:32 +01:00
parent 30b8ad51f4
commit 1287ecaeff

View file

@ -70,23 +70,25 @@ class quiz_overview_table extends quiz_attempts_report_table {
$this->add_separator(); $this->add_separator();
if (!empty($this->groupstudentsjoins->joins)) { if (!empty($this->groupstudentsjoins->joins)) {
$sql = "SELECT DISTINCT u.id $hasgroupstudents = $DB->record_exists_sql("
SELECT 1
FROM {user} u FROM {user} u
{$this->groupstudentsjoins->joins} {$this->groupstudentsjoins->joins}
WHERE {$this->groupstudentsjoins->wheres}"; WHERE {$this->groupstudentsjoins->wheres}
$groupstudents = $DB->get_records_sql($sql, $this->groupstudentsjoins->params); ", $this->groupstudentsjoins->params);
if ($groupstudents) { if ($hasgroupstudents) {
$this->add_average_row(get_string('groupavg', 'grades'), $this->groupstudentsjoins); $this->add_average_row(get_string('groupavg', 'grades'), $this->groupstudentsjoins);
} }
} }
if (!empty($this->studentsjoins->joins)) { if (!empty($this->studentsjoins->joins)) {
$sql = "SELECT DISTINCT u.id $hasstudents = $DB->record_exists_sql("
SELECT 1
FROM {user} u FROM {user} u
{$this->studentsjoins->joins} {$this->studentsjoins->joins}
WHERE {$this->studentsjoins->wheres}"; WHERE {$this->studentsjoins->wheres}
$students = $DB->get_records_sql($sql, $this->studentsjoins->params); " , $this->studentsjoins->params);
if ($students) { if ($hasstudents) {
$this->add_average_row(get_string('overallaverage', 'grades'), $this->studentsjoins); $this->add_average_row(get_string('overallaverage', 'grades'), $this->studentsjoins);
} }
} }