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

Slow query in completion_criteria_course.php cron() function

XMLWordPrintable

    • MOODLE_401_STABLE

      There is a slow query issue in the core Moodle code, specifically in the completion_criteria_course.php file. The problem occurs in the cron() function on line 155. This query takes an excessive amount of time, approximately 4 minutes, to complete even when it returns an empty set.

      $sql = "
      SELECT DISTINCT
      c.id AS course,
      cr.id AS criteriaid,
      ra.userid AS userid,
      cc.timecompleted AS timecompleted
      FROM

      {course_completion_criteria}

      cr
      INNER JOIN

      {course}

      c
      ON cr.course = c.id
      INNER JOIN

      {context}

      con
      ON con.instanceid = c.id
      INNER JOIN

      {role_assignments}

      ra
      ON ra.contextid = con.id
      INNER JOIN

      {course_completions}

      cc
      ON cc.course = cr.courseinstance
      AND cc.userid = ra.userid
      LEFT JOIN

      {course_completion_crit_compl}

      ccc
      ON ccc.criteriaid = cr.id
      AND ccc.userid = ra.userid
      WHERE
      cr.criteriatype = ".COMPLETION_CRITERIA_TYPE_COURSE."
      AND con.contextlevel = ".CONTEXT_COURSE."
      AND c.enablecompletion = 1
      AND ccc.id IS NULL
      AND cc.timecompleted IS NOT NULL
      ";

        1. screenshot-1.png
          screenshot-1.png
          99 kB
        2. mdl_course.csv
          49 kB
        3. mdl_course_modules.csv
          52 kB

            Unassigned Unassigned
            olgierddziminski Olgierd Dziminski
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:

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