Moodle
  1. Moodle
  2. MDL-22098

Broken caching in the grade item classes leads ot O(n) DB queries in the grader report

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.9.8
    • Fix Version/s: 1.9.9
    • Component/s: Gradebook
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE
    • Rank:
      26644

      Description

      I think the diff makes the problem clear.

      Index: lib/grade/grade_item.php
      @@ -871,7 +871,7 @@
            * @return object Grade_category
            */
           function load_item_category() {
      -        if (empty($this->category->id)) {
      +        if (empty($this->item_category->id)) {
                   $this->item_category = $this->get_item_category();
               }
               return $this->item_category;
      

      This was causing one DB query per category, per student, when showing the grader report, which is very, very bad.

      Andy, adding you as QA assignee, because I believe you are Mr Gradebook these days.

        Issue Links

          Activity

          Hide
          Tim Hunt added a comment -

          This issue has been fixed.

          However, there seems to be plenty more unnecessarily inefficient database usage in the gradebook.

          Andy, if you have time, can I suggest you do something to log every database query. For example just added

          echo "\n<pre>", htmlspecialchars($sql), "\n";
          debug_print_backtrace();
          echo "</pre>"; // DONOTCOMMIT
          

          at the top of Execute in lib/adodb/adodb.inc.php in 1.9. Then load various gradebook pages, and try to work out why is uses so many repeated queries (then fix it). Thanks.

          Show
          Tim Hunt added a comment - This issue has been fixed. However, there seems to be plenty more unnecessarily inefficient database usage in the gradebook. Andy, if you have time, can I suggest you do something to log every database query. For example just added echo "\n<pre>" , htmlspecialchars($sql), "\n" ; debug_print_backtrace(); echo "</pre>" ; // DONOTCOMMIT at the top of Execute in lib/adodb/adodb.inc.php in 1.9. Then load various gradebook pages, and try to work out why is uses so many repeated queries (then fix it). Thanks.
          Hide
          Andrew Davis added a comment -

          Thanks Tim. I'll QA this and open another item to look for more performance killers once I've finished off some other tasks.

          Show
          Andrew Davis added a comment - Thanks Tim. I'll QA this and open another item to look for more performance killers once I've finished off some other tasks.

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: