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

Memory exhausted when trying to view course certificate instance

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • None
    • 3.10
    • None
    • 3.9.2 (2020100700)
    • MOODLE_310_STABLE

      We've been hit hard by a problem at the learn.moodle.org staging site where after creating a new Course certificate module instance, the view.php script died with all the available memory exhausted.

      I was able to trace down the problem to mod_coursecertificate\output\view_page::export_for_template() which has the line:

      $data['userstoissue'] = count(helper::get_users_to_issue($this->certificate, $this->cm));
      

      that is expected to render a line like "Currently, X students meet this activity's access restrictions and will be issued with their certificate once they access it." with "X" being replaced with the number of users.

      There are several major issues with this:

      • The get_users_to_issue() method calls get_enrolled_users() which in turn calls get_records_sql() - that is, it loads all the records into the PHP memory. In our case, the query returns 43.000 records.
      • That call uses u.* to obtain all user record fields include the ones it never needs such as rich text profile description fields.
      • All these records and all their fields are loaded into the memory just to display their count.

      These deserves some optimisation, for example:

      • Use get_enrolled_sql() to construct more effective SQL.
      • Load only those user fields that are actually needed (using asterisk wildcard * is almost never a good idea).
      • Have a dedicated method to return the number of these candidate users for this case where we do not actually need to load them.

            mikelmartíncorrales Mikel Martín Corrales
            mudrd8mz David Mudrák (@mudrd8mz)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

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