@@ -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