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

Improve performance of course_section_add_cm_control()

XMLWordPrintable

    • MOODLE_39_STABLE
    • MOODLE_39_STABLE
    • MDL-68056-master
    • Hide

      Confirming the recent performance regression:

      1. Clone a new site, checking out 4e90332195f903 (this was pre-67585)
      2. Login in admin
      3. Install the site
      4. Create a course, but don't enrol any users. Just proceed to the course home page.
      5. Make sure editing is enabled!
      6. Reload the page a bunch of times, each time checking the DB reads/writes in the page footer. This should stabilise (you'll start seeing the same value again and again) and then occasionally increase and then come back down to the stablilised values again. Note down this stabilised read/write value (E.g. 73/0)
      1. Now, checkout 37b2ee3f6 and run the upgrade
      2. Once complete, go back to the course again.
      3. Enable editing if not already enabled.
      4. Again, reload the page a bunch of times, noting down the stabilised read/write value.
      5. Verify the read is WORSE (by 1) than the value you got after first installing on 4e90332195f903. The writes should be 0.

      Testing the improvements (simple case)

      1. Now, checkout master and run the upgrade
      2. Once complete, go back to the course again.
      3. Enable editing if not already enabled.
      4. Again, reload the page a bunch of times, noting down the stabilised read/write value.
      5. Verify the read is BETTER (by 1) than the value you got after first installing on 4e90332195f903 and BETTER (by 2) than the value you got after upgrading to 37b2ee3f6. The writes should be 0.

      Testing the improvements (disable the chooser in user prefs)

      1. Now, go to your user preferences -> course preferences and disable the activity chooser. As indicated on that preferences page, we expect to see a drop down instead now.
      2. Go to the course again
      3. Verify you see two selects under each section, instead of the 'Add an activity or resource' link.
      4. Using the controls in Topic 1, select a 'Page' resource
      5. Verify you're taken to the page edit form
      6. Fill out a name and description and save
      7. Verify you're taken back to the course home and can see a page resource in Topic 1.
      8. Using the controls in Topic 2, select a 'Chat' activity
      9. Verify you're taken to the chat edit form
      10. Fill out a name and save
      11. Verify you're taken back to the course home and can see a chat activity in Topic 2.
      12. Go back to user preferences -> course preferences and enable the activity chooser once again.
      13. Go back to the course and make sure you see the 'Add an activity or resource' link in each section
      14. Add a second page to Topic 1 and a second chat to Topic 2 , Verifying everything works and the activities/resources are created.

      Testing the improvements (disable course ajax in the theme)

      1. Now, in an editor of your choice, edit the file 'theme/boost/config.php'
      2. Near the top, below the 'require_once' call, add:

        $THEME->enablecourseajax = false;
        

      3. Save that file
      4. Now, go back to the course
      5. Make sure editing is still enabled
      6. Verify you see the drop down controls
      7. Add a page resource to Topic 1 and a chat activity to Topic 2 as you did before, verifying that the activities/resources can be added.
      Show
      Confirming the recent performance regression: Clone a new site, checking out 4e90332195f903 (this was pre-67585) Login in admin Install the site Create a course, but don't enrol any users. Just proceed to the course home page. Make sure editing is enabled! Reload the page a bunch of times, each time checking the DB reads/writes in the page footer. This should stabilise (you'll start seeing the same value again and again) and then occasionally increase and then come back down to the stablilised values again. Note down this stabilised read/write value (E.g. 73/0) Now, checkout 37b2ee3f6 and run the upgrade Once complete, go back to the course again. Enable editing if not already enabled. Again, reload the page a bunch of times, noting down the stabilised read/write value. Verify the read is WORSE (by 1) than the value you got after first installing on 4e90332195f903. The writes should be 0. Testing the improvements (simple case) Now, checkout master and run the upgrade Once complete, go back to the course again. Enable editing if not already enabled. Again, reload the page a bunch of times, noting down the stabilised read/write value. Verify the read is BETTER (by 1) than the value you got after first installing on 4e90332195f903 and BETTER (by 2) than the value you got after upgrading to 37b2ee3f6. The writes should be 0. Testing the improvements (disable the chooser in user prefs) Now, go to your user preferences -> course preferences and disable the activity chooser. As indicated on that preferences page, we expect to see a drop down instead now. Go to the course again Verify you see two selects under each section, instead of the 'Add an activity or resource' link. Using the controls in Topic 1, select a 'Page' resource Verify you're taken to the page edit form Fill out a name and description and save Verify you're taken back to the course home and can see a page resource in Topic 1. Using the controls in Topic 2, select a 'Chat' activity Verify you're taken to the chat edit form Fill out a name and save Verify you're taken back to the course home and can see a chat activity in Topic 2. Go back to user preferences -> course preferences and enable the activity chooser once again. Go back to the course and make sure you see the 'Add an activity or resource' link in each section Add a second page to Topic 1 and a second chat to Topic 2 , Verifying everything works and the activities/resources are created. Testing the improvements (disable course ajax in the theme) Now, in an editor of your choice, edit the file 'theme/boost/config.php' Near the top, below the 'require_once' call, add: $THEME->enablecourseajax = false; Save that file Now, go back to the course Make sure editing is still enabled Verify you see the drop down controls Add a page resource to Topic 1 and a chat activity to Topic 2 as you did before, verifying that the activities/resources can be added.
    • 3
    • Activity Sprint 8, Activity Sprint 9

      This method is called once per course section and currently handles a few cases:

      1. If $THEME->enablecourseajax == true AND $course->id == $this->page->course->id AND $usermodchooser == true (a user pref), then display the "Add an activity or resource" link allowing the chooser modal to be opened.
      2. If $THEME->enablecourseajax == true AND $course->id == $this->page->course->id AND $usermodchooser == false (a user pref), then display fallback 1 - a control including two lists of resources and activities which, when selected, take the user to the creation page for that module.
      3. If $THEME->enablecourseajax == true AND $course->id != $this->page->course->id, then display fallback 1 - a control including two lists of resources and activities, which, when selected, take the user to the creation page for that module.
      4. If $THEME->enablecourseajax == false, then display fallback 1 - a control including two lists of resources and activities which, when selected, take the user to the creation page for that module.
      5. If JS is disabled in the browser (not a case we support any more), then fallback 2 is shown - a control including the same two lists of resources and activities plus a 'Go' submit button. The user needs to select the activity/resource and then click 'Go' in this fallback case.

      Fallback 1 and 2 are handled by the same code - it's just that when loaded in a browser without js enabled, the 'Go' button is shown (it's inside a <noscript> tag)

      The way this method is currently structured is such that we always generate the fallback control HTML. I.e. every time this method is called, which is once per course section, this is created. Then, if the theme supports course ajax (provided the course also matches the page course, as above), then we wrap that entire fallback HTML inside <noscript> tags and append the link control to the output string before returning.

      I think we can clean this up. We don't have any obligation to support the "I disabled JS in my browser" case as we have been JS dependent for some time now. We should therefore be able to do one of two things depending only on the courseajax support:

      1. Render fallback control 1 in cases where:
        • The theme sets $THEME->enablecourseajax to false or;
        • $THEME->enablecourseajax is true but course doesn't match the this->page->course or;
        • The user has disabled the modchooser in their user prefs.
        • We're running in Behat, since many behat setup steps expect the step I add a "x" to section "y" and I fill the form with to work without JS.
      2. Render the link control in cases where the $THEME->enablecourseajax is true and the course matches the $this->page->course and the user preference allows for the chooser.

      This would mean we're likely going to reduce DB calls, and reduce the volume of code we're running on every course home load - when editing is enabled, of course.

            jaked Jake Dallimore
            jaked Jake Dallimore
            Carlos Escobedo Carlos Escobedo
            Jun Pataleta Jun Pataleta
            Simey Lameze Simey Lameze
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 14 minutes
                1d 14m

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