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

Extending navigation from report progress is inefficient

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      • Run the unit tests lib/tests/completion_advanced_test.php
      1. Enable enablecompletion
      2. Enable the completion tracking on a course, and visit the course
      3. Make sure you can see 'Activity completion' under 'Reports' in 'Course administration' if you have activities with completion tracking enabled
      4. Make sure you CANNOT see 'Activity completion' under 'Reports' in 'Course administration' if you DO NOT have activities with completion tracking enabled
      Show
      Run the unit tests lib/tests/completion_advanced_test.php Enable enablecompletion Enable the completion tracking on a course, and visit the course Make sure you can see 'Activity completion' under 'Reports' in 'Course administration' if you have activities with completion tracking enabled Make sure you CANNOT see 'Activity completion' under 'Reports' in 'Course administration' if you DO NOT have activities with completion tracking enabled
    • Affected Branches:
      MOODLE_24_STABLE, MOODLE_25_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-39536-master

      Description

      While debugging MDL-37773, I came across report_progress_extend_navigation_course() which is highly inefficient when it comes to adding nodes to the navigation.

      If activity completion is enabled on the course, then it gets all the activities just to ensure that at least one has completion enabled. This is a massive processing where a simple DB->record_exists would be just enough.

      $showonnavigation = ($showonnavigation && $completion->is_enabled() && ($completion->get_activities())>0);
      

      Will call:

          public function get_activities($modinfo=null) {
              global $DB;
       
              // Obtain those activities which have completion turned on
              $withcompletion = $DB->get_records_select('course_modules', 'course='.$this->course->id.
                ' AND completion<>'.COMPLETION_TRACKING_NONE);
              if (!$withcompletion) {
                  return array();
              }
       
              // Use modinfo to get section order and also add in names
              if (empty($modinfo)) {
                  $modinfo = get_fast_modinfo($this->course);
              }
              $result = array();
              foreach ($modinfo->sections as $sectioncms) {
                  foreach ($sectioncms as $cmid) {
                      if (array_key_exists($cmid, $withcompletion)) {
                          $result[$cmid] = $withcompletion[$cmid];
                          $result[$cmid]->modname = $modinfo->cms[$cmid]->modname;
                          $result[$cmid]->name    = $modinfo->cms[$cmid]->name;
                      }
                  }
              }
       
              return $result;
          }
      

      loading modinfo for each module.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              fred Frédéric Massart
              Reporter:
              fred Frédéric Massart
              Peer reviewer:
              Sam Marshall
              Integrator:
              Dan Poltawski
              Tester:
              Andrew Davis
              Participants:
              Component watchers:
              Sam Marshall, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                8/Jul/13