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

Event Monitor loads every course context and builds strings on every page view

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Note: As this is performance related issue, it should be tested on a site with more than 2500 courses (which is the default size of the contexts cache). The Moodle's in-built site generator can make such a test site for you (it takes some time). Let the performance info be displayed in the footer and watch the number of DB reads.

      1. Log in as an administrator.
      2. Enable the event monitor [Site administration ► Reports ► Event monitoring rules].
      3. Add some site level rules such as a course was updated.
      4. Go to the event monitoring page. User menu -> preferences -> Event monitoring.
      5. Make sure that you can see "Site" in the course select box.
      6. Log out and log in as a teacher.
      7. Go to the event monitoring page. User menu -> preferences -> Event monitoring.
      8. Make sure that you can not see "Site" in the couse select box.
      9. Check that you can subscribe to all of the rules. Make sure to change the course.
      10. Logout and log in as a student.
      11. Go to the preferences page. Make sure that there is no link to the event monitor.
      12. Try going directly to the page - admin/tool/monitor/index.php.
      13. Check that you see a message saying something like "You do not have permission to subscibe to any events."
      14. As an admin, in the course the student is enrolled in, create a override for the student role, giving the permission ‘tool/monitor:subscribe’.
      15. Log in as the student
      16. Confirm you can go to the event monitoring page. User menu -> preferences -> Event monitoring.
      17. Logout and log in as a guest.
      18. Manually go to the event monitor page (admin/tool/monitor/index.php).
      19. Check that you see a message saying something like "You do not have permission to subscibe to any events."
      20. Assign a user to the Manager role at a course category level.
      21. Login as that user.
      22. Go to the event monitoring page. User menu -> preferences -> Event monitoring.
      23. Make sure that you can not see "Site" in the couse select box.
      24. Make sure that you can see the courses from that category.
      Show
      Note: As this is performance related issue, it should be tested on a site with more than 2500 courses (which is the default size of the contexts cache). The Moodle's in-built site generator can make such a test site for you (it takes some time). Let the performance info be displayed in the footer and watch the number of DB reads. Log in as an administrator. Enable the event monitor [Site administration ► Reports ► Event monitoring rules] . Add some site level rules such as a course was updated. Go to the event monitoring page. User menu -> preferences -> Event monitoring. Make sure that you can see "Site" in the course select box. Log out and log in as a teacher. Go to the event monitoring page. User menu -> preferences -> Event monitoring. Make sure that you can not see "Site" in the couse select box. Check that you can subscribe to all of the rules. Make sure to change the course. Logout and log in as a student. Go to the preferences page. Make sure that there is no link to the event monitor. Try going directly to the page - admin/tool/monitor/index.php. Check that you see a message saying something like "You do not have permission to subscibe to any events." As an admin, in the course the student is enrolled in, create a override for the student role, giving the permission ‘tool/monitor:subscribe’. Log in as the student Confirm you can go to the event monitoring page. User menu -> preferences -> Event monitoring. Logout and log in as a guest. Manually go to the event monitor page (admin/tool/monitor/index.php). Check that you see a message saying something like "You do not have permission to subscibe to any events." Assign a user to the Manager role at a course category level. Login as that user. Go to the event monitoring page. User menu -> preferences -> Event monitoring. Make sure that you can not see "Site" in the couse select box. Make sure that you can see the courses from that category.
    • Affected Branches:
      MOODLE_29_STABLE, MOODLE_31_STABLE, MOODLE_32_STABLE
    • Fixed Branches:
      MOODLE_31_STABLE, MOODLE_32_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      wip-MDL-51833-master
    • Sprint:
      3.3 sprint 4

      Description

      We were testing out Event Monitor on a test copy of our site, and noticed it does pretty horrific things.

      So in 2.9, hooks were added for admin tools to add user profile settings. This was used to add a Event Monitor preference page to the user profile. Unfortunately, this was done in a very, very painful way. In admin/tool/monitor/lib.php::tool_monitor_get_user_courses():

      1. Get an array of every course the user has 'tool/monitor:subscribe' in, using get_user_capability_course()
        1. This method gets every course context, instantiates it, then checks its capability, and if it has it, stores it in an array
      2. Then, when we have the list of courses, for each one creates a list of custom formatted strings (to build an options list)

      Now that may be the best way to build the dropdown list given the current access library. The real problem is that tool_monitor_extend_navigation_user_settings() builds the dropdown list to check and see if there are any courses the user could possibly have access to. It then discards it and adds a single link to the profile page.

      For an admin user on our site, that means that every page takes about 45 seconds to load. It adds a few seconds to most users (who have access to none or a few courses)

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                25 Vote for this issue
                Watchers:
                35 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  13/Mar/17