Uploaded image for project: 'Plugins'
  1. Plugins
  2. CONTRIB-5546

Journal is slow because of db querys

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.6.7, 2.7.4, 2.8.2
    • Fix Version/s: None
    • Component/s: Module: Journal
    • Labels:
      None
    • Database:
      Oracle
    • Workaround:
      Hide

      Replace the foreach code from the description below for that:

          $canadd = get_users_by_capability($context, 'mod/journal:addentries');
          $entriesmanager = get_users_by_capability($context, 'mod/journal:manageentries');
       
          // remove unenrolled participants
          foreach ($journals as $userid => $notused) {
       
              if (!isset($entriesmanager[$userid]) && !isset($canadd[$userid])) {
                  unset($journals[$userid]);
              }
          }
      

      Show
      Replace the foreach code from the description below for that: $canadd = get_users_by_capability($context, 'mod/journal:addentries'); $entriesmanager = get_users_by_capability($context, 'mod/journal:manageentries');   // remove unenrolled participants foreach ($journals as $userid => $notused) {   if (!isset($entriesmanager[$userid]) && !isset($canadd[$userid])) { unset($journals[$userid]); } }
    • Affected Branches:
      MOODLE_26_STABLE, MOODLE_27_STABLE, MOODLE_28_STABLE

      Description

      Hi,
      When showing Journal as a teacher it counts the number of entries. To calculate that it counts all the entries and removes the ones from unenrolled users. This causes that the number of querys increase 5 querys per entry.

      We are using Oracle as DB and Moodle 2.6.7. We've realised that oracle can be the point but not the Moodle version.

      Testing that it ha for view.php:
      88 reads for a brand new journal activity created.
      850 for a journal with about 150 users and entries.

      All this is caused by the following code inside journal_count_entries function:

      foreach ($journals as $key => $user) {
       
              $canadd = has_capability('mod/journal:addentries', $context, $user);
              $entriesmanager = has_capability('mod/journal:manageentries', $context, $user);
       
              if (!$entriesmanager && !$canadd) {
                  unset($journals[$key]);
              }
          }
      

      I think this have to be replaced by getting all users enroled and matching both $journals and $userenroled arrays.

        Attachments

          Activity

            People

            Assignee:
            dmonllao David Monllaó
            Reporter:
            pferre22 Pau Ferrer
            Participants:
            Component watchers:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: