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

Unnecessary calls to "count()" can be optimized to improve performance

XMLWordPrintable

    • MOODLE_22_STABLE, MOODLE_23_STABLE, MOODLE_24_STABLE
    • MOODLE_22_STABLE, MOODLE_23_STABLE, MOODLE_24_STABLE
    • MDL-36761_loop
    • Hide

      This code is pretty conclusively covered by the unit tests (phpunit grade_category_testcase lib/grade/tests/grade_category_test.php)

      Show
      This code is pretty conclusively covered by the unit tests (phpunit grade_category_testcase lib/grade/tests/grade_category_test.php)

      In the function "apply_limit_rules()" in "/lib/grade/grade_category.php", the "count()" function is called repeatedly on a variable that does not change. For large data sets, this can cause an performance hit.
      Consider changing so that count is called only once:
      From:

      $i = 1;
      while ($originalindex+$i < count($grade_keys)) {
          $possibleitemid = $grade_keys[$originalindex+$i];
          $i++;
      ...

      To:

      $i = 1;
      $gradekeycount = count($grade_keys);
      while ($originalindex+$i < $gradekeycount) {
          $possibleitemid = $grade_keys[$originalindex+$i];
          $i++;
      ...

            andyjdavis Andrew Davis
            mchurch Mike Churchward
            Ankit Agarwal Ankit Agarwal
            Sam Hemelryk Sam Hemelryk
            Frédéric Massart Frédéric Massart
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

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