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

User/Custom Profile Fields index.php page loads extremely slow when the number of fields increases on LMS.

XMLWordPrintable

    • MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE
    • MOODLE_311_STABLE
    • MDL-67709-master
    • Hide

      Compare page load time on user/profile/index.php before and after adding fix.

      Tests before adding fix:

      1. Test load on user/profile/index.php by adding 40 or more custom profile fields and 1000 or more users with user info data populated for each of the user info fields.
      2. Once users have populated custom profile field data, reload user/profile/index.php and take note of the load time.
      3. Page loads in way over 1 second and can take 80 seconds to load on an LMS with 25,000 users and 80+ custom profile fields with data values populated.

      Tests after adding fix:

      1. Test load on user/profile/index.php by adding 40 or more custom profile fields and 1000 or more users with user info data populated for each of the user info fields.
      2. Once users have populated custom profile field data, reload user/profile/index.php and take note of the load time.
      3. Page loads in less than 1 second.
      4. Compare load times for before and after. Adding the fix significantly changes the load time and the page loads much faster.
      5. Increasing the number of fields and users should not significantly affect the load time of the page.
      6. Variable is unused so it does not break the page or result in any error.
      Show
      Compare page load time on user/profile/index.php before and after adding fix. Tests before adding fix: Test load on user/profile/index.php by adding 40 or more custom profile fields and 1000 or more users with user info data populated for each of the user info fields. Once users have populated custom profile field data, reload user/profile/index.php and take note of the load time. Page loads in way over 1 second and can take 80 seconds to load on an LMS with 25,000 users and 80+ custom profile fields with data values populated. Tests after adding fix: Test load on user/profile/index.php by adding 40 or more custom profile fields and 1000 or more users with user info data populated for each of the user info fields. Once users have populated custom profile field data, reload user/profile/index.php and take note of the load time. Page loads in less than 1 second. Compare load times for before and after. Adding the fix significantly changes the load time and the page loads much faster. Increasing the number of fields and users should not significantly affect the load time of the page. Variable is unused so it does not break the page or result in any error.

      We discovered that the User Profile Fields index.php (user/profile/index.php) page loads extremely slow on our Moodle LMS when we increased the number of custom profile fields on the LMS.

      Our LMS has about 80 custom profile fields with about 25,000 users. The page progressively got slower the more fields and users we added onto the site until it started taking over 80+ seconds to load the index page.

      After some further investigation into the index.php code we discovered a line of code that is not used that add's a huge load to the page because it makes a DB call in a nested foreach loop on each custom profile field.

      The function that contains this unused variable is  profile_field_icons() :

       

      function profile_field_icons($field) {        
        global $CFG, $USER, $DB, $OUTPUT;    
        $strdelete   = get_string('delete');        
        $strmoveup   = get_string('moveup');        
        $strmovedown = get_string('movedown');        
        $stredit     = get_string('edit');    
        $fieldcount = $DB->count_records('user_info_field', array('categoryid' =>       $field->categoryid));       
        $datacount  = $DB->count_records('user_info_data', array('fieldid' => $field->id)); //This variable is never used anywhere
      //commenting out the unused variable $datacount takes the page from 80 seconds to 0.4seconds on our LMS  
      

       

       

      The function profile_field_icons() is then called in a nested foreach loop and it's easy to see why returning a data count on each of the 80 custom profile fields for 25, 000 data values each can significantly slow down the page.

      Since the variable is not used I commented the whole line out and the page now takes 0.4 seconds to load a significant difference from 80+ seconds to load.

      Looking back further into Moodle's code repository we discovered that the variable $datacount had been used in the past but more recently these checks to use it have been removed. See below from 2007

      https://github.com/moodle/moodle/commit/d0c33889c501a461cb92ffbda0c71f7a82843cde#diff-a5ead404e182b6aed1b9997ed0d880d8

      Refer to lines number 301 and 308.

       

      Our current Moodle version is 3.4.9 but this unused variable seems to exist on all newer moodle versions

            ilyatregubov Ilya Tregubov
            muchenjanamumba Muchenja Namumba
            Votes:
            0 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 minutes
                3m

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