Moodle
  1. Moodle
  2. MDL-19880

Course import runs out of memory when user has update capability on large number of courses

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9.8
    • Fix Version/s: 1.9.9, 2.0
    • Component/s: Course
    • Labels:
      None
    • Database:
      PostgreSQL
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE, MOODLE_20_STABLE
    • Rank:
      31410

      Description

      Import activities tool runs out of memory when trying to load a large number of courses user has taught in, encountered within environment running 2500 courses logged in as administrator with memory_limit of 96M.

      Upon selecting import within any course the following error is displayed: "PHP Fatal error: Allowed memory size of 100663296 bytes exhausted (tried to allocate 86 bytes) in /moodle/lib/dmllib.php on line 728, referer: http://<moodlesite>/course/view.php?id=1225".

      The file course/import/activities/mod.php loads all courses where user has permission 'moodle/course:update' but does not restrict fields causing the result set to become quite large in certain scenarios.

      This bug may be difficult to replicate due to number of courses in my environment but you will need to create a large number of courses, be logged in with moodle/course:update permissions on all courses and select import course on any course.

      I've attached a patch to restrict fields to id and fullname, which are the only fields required to import activities.

        Issue Links

          Activity

          Hide
          Luke Tucker added a comment -

          I don't believe this issue is actually a duplicate - there is another query a few lines above the query fixed in MDL-17497 which is triggered for users with update permissions on a lot of courses such as administrators.

          The query causing the memory issue here is on line 32 of course/import/activities/mod.php:
          $taught_courses = get_records_list('course', 'id', $tcourseids);

          Thanks,
          Luke

          Show
          Luke Tucker added a comment - I don't believe this issue is actually a duplicate - there is another query a few lines above the query fixed in MDL-17497 which is triggered for users with update permissions on a lot of courses such as administrators. The query causing the memory issue here is on line 32 of course/import/activities/mod.php: $taught_courses = get_records_list('course', 'id', $tcourseids); Thanks, Luke
          Hide
          Tim Lock added a comment -

          Please see attached patch for Moodle 1.9 and 2.0

          Show
          Tim Lock added a comment - Please see attached patch for Moodle 1.9 and 2.0
          Hide
          Tim Lock added a comment -

          Please allocation this to a bug in Moodle 2 Preview 3.

          Show
          Tim Lock added a comment - Please allocation this to a bug in Moodle 2 Preview 3.
          Hide
          Martin Dougiamas added a comment -

          Seems like a no brainer +1 from me.

          Show
          Martin Dougiamas added a comment - Seems like a no brainer +1 from me.
          Hide
          Martin Dougiamas added a comment -

          Checked in to 1.9.9 and 2.0. Thanks guys!

          Show
          Martin Dougiamas added a comment - Checked in to 1.9.9 and 2.0. Thanks guys!
          Hide
          Matthew Davidson added a comment -

          needs to be changed from
          $taught_courses = get_records_list('course', 'id', $tcourseids, '', 'id, fullname');
          to
          $taught_courses = get_records_list('course', 'id', $tcourseids, 'id, fullname');

          breaks the sql for the list of imported courses

          Show
          Matthew Davidson added a comment - needs to be changed from $taught_courses = get_records_list('course', 'id', $tcourseids, '', 'id, fullname'); to $taught_courses = get_records_list('course', 'id', $tcourseids, 'id, fullname'); breaks the sql for the list of imported courses
          Hide
          Alan Trick added a comment -

          Matthew, I just created a separate report for the regression error (MDL-22740). Go and vote for it if you want it fixed soon.

          Show
          Alan Trick added a comment - Matthew, I just created a separate report for the regression error ( MDL-22740 ). Go and vote for it if you want it fixed soon.

            People

            • Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: