-
Improvement
-
Resolution: Unresolved
-
Minor
-
None
-
4.5, 4.5.1, 4.5.2
-
Any
-
MOODLE_405_STABLE
The slowness is due to the fact that in the form (completion_form.php) for the "Course prerequisite completion criteria" section, there is a line of code that is absolutely inefficient for the purpose it is used for:
$hasselectablecourses = core_course_category::search_courses(['onlywithcompletion' => true], ['limit' => 2]); |
The variable $hasselectablecourses is then used only in the if statement to decide whether to display the course selection menu or not.
The function core_course_category::search_courses is absolutely inefficient because, despite the limit parameter, in cases where the "coursecat" cache does not contain the necessary elements, it will retrieve all courses with active completion. For all results, contexts and other elements will be unnecessarily computed, only to finally perform an array slice on all results.
With 82,919 courses present, the page often risks taking over a minute to load and potentially timing out.
Considering that $hasselectablecourses is only meant to determine whether at least one other course with active completion exists, excluding the current course, wouldn't it be more efficient to:
$hasselectablecourses = $DB->record_exists_sql("SELECT id from {course} where ENABLECOMPLETION = ? and id != ?",array(1,$course->id)); |
- mentioned in
-
Page Loading...