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

Web service perf: get_courses_by_field loads contexts, categories individually

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.8
    • Fix Version/s: 3.8
    • Component/s: Web Services
    • Labels:
      None
    • Testing Instructions:
      Hide

      You need a Moodle setup configured to allow mobile app access, and a test user account (not admin) who is permitted to use it. The user must be enrolled on at least one course.

      1. Using Moodle Desktop, connect to your site with the test account.
      2. Press Ctrl+Shift+I (Cmd+Opt+I for Macs) to open the Chrome dev tools.
      3. Go to the network panel.
      4. Clear the panel.
      5. Click into one of the courses the user is enrolled in.
      6. In the network panel, you should see EITHER a request for wsfunction=core_course_get_courses_by_field OR a request for wsfunction=tool_mobile_call_external_functions, where if you look at the details on the 'Headers' panel, one of the functions is core_course_get_courses_by_field.
      7. Look at the parameters for the request or for the specific function. There should be one like 'ids' with a comma-separated list, such as '3,1'. Make a note of the ids (and the request number, if it's the grouped one).
      8. Look at the response (for the specific function if there were multiple). Check that:
        • The response should be successful.
        • It should have a 'courses' value with an entry for each course id from the list (3, 1 in the above example).
      Show
      You need a Moodle setup configured to allow mobile app access, and a test user account (not admin) who is permitted to use it. The user must be enrolled on at least one course. Using Moodle Desktop, connect to your site with the test account. Press Ctrl+Shift+I (Cmd+Opt+I for Macs) to open the Chrome dev tools. Go to the network panel. Clear the panel. Click into one of the courses the user is enrolled in. In the network panel, you should see EITHER a request for wsfunction=core_course_get_courses_by_field OR a request for wsfunction=tool_mobile_call_external_functions, where if you look at the details on the 'Headers' panel, one of the functions is core_course_get_courses_by_field. Look at the parameters for the request or for the specific function. There should be one like 'ids' with a comma-separated list, such as '3,1'. Make a note of the ids (and the request number, if it's the grouped one). Look at the response (for the specific function if there were multiple). Check that: The response should be successful. It should have a 'courses' value with an entry for each course id from the list (3, 1 in the above example).
    • Affected Branches:
      MOODLE_38_STABLE
    • Fixed Branches:
      MOODLE_38_STABLE
    • Pull Master Branch:
      MDL-65931-master

      Description

      The core_course_get_courses_by_field web service function is called from the mobile app when you view a course. It retrieves data for all courses you are enrolled in.

      The function uses contexts for each course, and does not preload them. As a result, it makes more queries than necessary (1 query per course), which could reduce performance or increase load on the database. There is a standard mechanism to preload contexts, so this should be used.

      In addition it loads category information and, again, does this one at a time although there is a mechanism to load them into cache in bulk.

      I tested on one of our systems with a copy of live course data, using an account that is enrolled in 22 courses (more than typical). Preloading these two categories of data reduces the numer of queries from 427 to 398, a reduction of 29 queries or about 7%. Not a big improvement but since the fix is very simple, I think it might be worth doing.

      Fun stats from our system:

      • Our most-enrolled active user is enrolled on 505 courses - this seems to be a real person not a test account, wtf. (Staff member not student obviously.)
      • Median is 6 courses, top 10% is 12, top 1% is 46.

        Attachments

          Activity

            People

            Assignee:
            quen Sam Marshall
            Reporter:
            quen Sam Marshall
            Peer reviewer:
            Juan Leyva
            Integrator:
            Eloy Lafuente (stronk7)
            Tester:
            Eloy Lafuente (stronk7)
            Participants:
            Component watchers:
            Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              18/Nov/19

                Time Tracking

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 20 minutes
                1h 20m