Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-84830

Course Completion Settings page is very slow and timing out due to thousands of courses

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.5, 4.5.1, 4.5.2
    • Course completion

      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)); 

            Unassigned Unassigned
            polder84 Enrico
            Votes:
            4 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.