-
Bug
-
Resolution: Fixed
-
Minor
-
3.5.10, 3.6.8, 3.7.1
-
MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE
-
MOODLE_311_STABLE
-
MDL-67709-master -
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
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
- has a non-specific relationship to
-
MDL-79311 Deprecate custom user profile field plugins and convert to customfields api
-
- Open
-