Skip to content

Commit bdc8394

Browse files
committed
MDL-82545 gradereport_grader: Limit grades per page
This replaces the limit on the number of students per page with a number of grades per page, to take into account the number of grade items on a course.
1 parent d7cb2a6 commit bdc8394

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

grade/report/grader/index.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
require_once($CFG->dirroot.'/grade/lib.php');
2929
require_once($CFG->dirroot.'/grade/report/grader/lib.php');
3030

31+
// This report may require a lot of memory and time on large courses.
32+
raise_memory_limit(MEMORY_HUGE);
33+
set_time_limit(120);
34+
3135
$courseid = required_param('id', PARAM_INT); // course id
3236
$page = optional_param('page', 0, PARAM_INT); // active page
3337
$edit = optional_param('edit', -1, PARAM_BOOL); // sticky editting mode
@@ -191,8 +195,9 @@
191195
$pagingoptions = array_unique($pagingoptions);
192196
sort($pagingoptions);
193197
$pagingoptions = array_combine($pagingoptions, $pagingoptions);
194-
if ($numusers > grade_report_grader::MAX_STUDENTS_PER_PAGE) {
195-
$pagingoptions['0'] = grade_report_grader::MAX_STUDENTS_PER_PAGE;
198+
$maxusers = $report->get_max_students_per_page();
199+
if ($numusers > $maxusers) {
200+
$pagingoptions['0'] = $maxusers;
196201
} else {
197202
$pagingoptions['0'] = get_string('all');
198203
}
@@ -215,7 +220,7 @@
215220
);
216221

217222
// The number of students per page is always limited even if it is claimed to be unlimited.
218-
$studentsperpage = $studentsperpage ?: grade_report_grader::MAX_STUDENTS_PER_PAGE;
223+
$studentsperpage = $studentsperpage ?: $maxusers;
219224
$footercontent .= html_writer::div(
220225
$OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl),
221226
'col'

grade/report/grader/lib.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ class grade_report_grader extends grade_report {
105105
/** @var int Maximum number of students that can be shown on one page */
106106
public const MAX_STUDENTS_PER_PAGE = 5000;
107107

108+
/**
109+
* @var int The maximum number of grades that can be shown on one page.
110+
*
111+
* More than this causes issues for the browser due to the size of the page.
112+
*/
113+
public const MAX_GRADES_PER_PAGE = 200000;
114+
108115
/** @var int[] List of available options on the pagination dropdown */
109116
public const PAGINATION_OPTIONS = [20, 100];
110117

@@ -466,9 +473,10 @@ public function load_users(bool $allusers = false) {
466473
$this->userwheresql
467474
$this->groupwheresql
468475
ORDER BY $sort";
469-
// We never work with unlimited result. Limit the number of records by MAX_STUDENTS_PER_PAGE if no other limit is specified.
476+
// We never work with unlimited result. Limit the number of records by $this->get_max_students_per_page() if no other limit
477+
// is specified.
470478
$studentsperpage = ($this->get_students_per_page() && !$allusers) ?
471-
$this->get_students_per_page() : static::MAX_STUDENTS_PER_PAGE;
479+
$this->get_students_per_page() : $this->get_max_students_per_page();
472480
$this->users = $DB->get_records_sql($sql, $params, $studentsperpage * $this->page, $studentsperpage);
473481

474482
if (empty($this->users)) {
@@ -526,6 +534,18 @@ protected function get_allgradeitems() {
526534
return $this->allgradeitems;
527535
}
528536

537+
/**
538+
* Return the maximum number of students we can display per page.
539+
*
540+
* This is based on the number of grade items on the course, to limit the overall number of grades displayed on a single page.
541+
* Trying to display too many grades causes browser issues.
542+
*
543+
* @return int
544+
*/
545+
public function get_max_students_per_page(): int {
546+
return round(static::MAX_GRADES_PER_PAGE / count($this->get_allgradeitems()));
547+
}
548+
529549
/**
530550
* we supply the userids in this query, and get all the grades
531551
* pulls out all the grades, this does not need to worry about paging

0 commit comments

Comments
 (0)