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

Loading custom profile data into user object requires many DB calls

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.4
    • 3.3
    • User management
    • MOODLE_33_STABLE
    • MOODLE_34_STABLE
    • wip-MDL-60029-master
    • Hide

      Since this is an improvement issue, to verify value, you need to test before and after pulling code.

      1. Create a number of custom user profile fields (at least four). One of each type is best.
      2. Edit your test user profile and complete data for each profile field.
      3. Turn on full performance info in the Site admin / Development / Debugging section.
      4. Go to your profile screen and view the number of database reads in the footer. Refresh the page several times. Record this number.
      5. Pull the new code onto the site (alternatively revert commits from this issue)
      6. Go to your profile screen and view the number of database reads in the footer. Refresh the page several times. Record this number.
      7. Verify that the new number of reads is less than the previous recorded number.

      On a site with four profile fields, I recorded a drop of 11 database reads. This number will go up and down with the number of defined profile fields. Multiply this by the number of users loading profile fields on a site at any time, and this could be significant.

      Show
      Since this is an improvement issue, to verify value, you need to test before and after pulling code. Create a number of custom user profile fields (at least four). One of each type is best. Edit your test user profile and complete data for each profile field. Turn on full performance info in the Site admin / Development / Debugging section. Go to your profile screen and view the number of database reads in the footer. Refresh the page several times. Record this number. Pull the new code onto the site (alternatively revert commits from this issue) Go to your profile screen and view the number of database reads in the footer. Refresh the page several times. Record this number. Verify that the new number of reads is less than the previous recorded number. On a site with four profile fields, I recorded a drop of 11 database reads. This number will go up and down with the number of defined profile fields. Multiply this by the number of users loading profile fields on a site at any time, and this could be significant.

      Currently, the user/profile/lib.php:profile_load_data API function uses many individual database functions when called for a user. This could be improved by getting most of the data with one call in the API function, and then feeding that data down the calling chain.

      The number of calls is dependent on the number of custom fields defined per site.

      With any one profile field, there is:

      • profile_load_data->get_records
      • profile_fieldbase::load_data->get_record x 2

      The two get record calls, are repeated for each field, meaning there is 2 * the number of fields database calls for each call to this API function.

      With some code improvements, this could be reduced to one call total.

            mchurch Mike Churchward
            mchurch Mike Churchward
            Marina Glancy Marina Glancy
            Jun Pataleta Jun Pataleta
            Jun Pataleta Jun Pataleta
            Votes:
            1 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved:

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