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

No limit on number of users when viewing roles assigned in a specific context, resulting with php memory error

XMLWordPrintable

    • MOODLE_27_STABLE
    • MOODLE_27_STABLE, MOODLE_28_STABLE
    • Hide
      1. Create a M size course using tool_generator
      2. Go to admin/roles/assign.php?contextid=XXX&roleid=5
      3. In the existing users select box you SHOULD see the message Too many users (1000) to show
      4. Use the filter to look for test course user 22
      5. Now you SHOULD see a few users
      6. Remove a couple of these users
      7. You SHOULD NOT see any error
      Show
      Create a M size course using tool_generator Go to admin/roles/assign.php?contextid=XXX&roleid=5 In the existing users select box you SHOULD see the message Too many users (1000) to show Use the filter to look for test course user 22 Now you SHOULD see a few users Remove a couple of these users You SHOULD NOT see any error

      When attempting to view /admin/roles/assign.php?contextid=177&roleid=5
      the following error message is received:
      Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /vle/www_root/lib/dml/pgsql_native_moodle_database.php on line 787

      On this particular system the sql: SELECT ra.id AS raid,u.id,u.firstnamephonetic,u.lastnamephonetic,u.middlename,u.alternatename,u.firstname,u.lastname,u.username,u.idnumber,ra.contextid,ra.component
      FROM mdl_role_assignments ra
      JOIN mdl_user u ON u.id = ra.userid
      JOIN mdl_context ctx ON ra.contextid = ctx.id
      WHERE u.id <> 1
      AND u.deleted = 0
      AND u.confirmed = 1
      AND ctx.id IN (177,86,97,95,1)
      AND ra.roleid = 5
      ORDER BY ctx.depth DESC, ra.component, u.lastname, u.firstname, u.id

      produces 60043 rows.

      The error is due to the memory usage of the arrays used to process these results.

      In other admin screens the $this->maxusersperpage variable is used to prevent this processing being attempted where tuples to display may cause such issues.

      Moving original testing instructions here
      Find a context where you have around 40,000 users (my test had 40,921 users, one with 26,058 worked without error) assigned to a particular role. I used the query:
      select count(1),contextid, roleid from mdl_role_assignments
      group by contextid,roleid
      order by 1 desc

      and then request /admin/roles/assign.php?contextid=<contextid>&roleid=<roleid>, and with debugging on you should get the error: 'Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 9 bytes) in /vle/www_root/lib/dml/pgsql_native_moodle_database.php on line 787' or similar depending on your script location.

      Once this change is applied you should not receive this error and the page should display correct, and rather than displaying the list of users with the role currently assigned the box should display: 'Too many users (xxxxx) to show Please use search'

            rtcn2 Rod Norfor
            rtcn2 Rod Norfor
            Tim Hunt Tim Hunt
            David Monllaó David Monllaó
            David Monllaó David Monllaó
            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.