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

Quiz queue_quiz_open_notification_tasks_for_users can be very slow

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 5.0.2, 4.5.6
    • Quiz, Tasks
    • MOODLE_405_STABLE, MOODLE_500_STABLE
    • MDL-85764-quiz-notification-MOODLE_405_STABLE
    • MDL-85764-quiz-notification-MOODLE_500_STABLE
    • MDL-85764-quiz-notification
    • Hide

      Creating a test course with enough overrides to trigger this slowness is cumbersome and the performance improvement should be clear from code logic, so just confirm the notifications still work as intended for groups (which is covered by unit tests).

      For completeness I've included modified testing instructions from MDL-79718:

      Test that group notifications still work as intended

      1. Log in as a teacher.
      2. Create a course and enrol a student (student1).
      3. Create a new group (group1)
      4. Assign student1 to a group (group1)
      5. Create a quiz with an open date one day from now (48 is the threshold).
      6. Go to the quiz.
      7. Go to More->Overrides.
      8. Add a group override for group1 and set the 'Open the quiz' date one week from now.
      9. Run this scheduled task to queue the open notification task:

        php admin/cli/scheduled_task.php --execute=\\mod_quiz\\task\\queue_all_quiz_open_notification_tasks

      10. Run adhoc tasks:

        php admin/cli/adhoc_task.php -e

      11. Log in as student1
      12. CONFIRM that you do not have a new notification for the quiz opening.
      13. Log in as the teacher
      14. Adjust the override date for the group to one hour from now.
      15. Run the scheduled task again (see above).
      16. Run cron (see above).
      17. Log in as student1
      18. CONFIRM that you have a new notification for the quiz opening.
      Show
      Creating a test course with enough overrides to trigger this slowness is cumbersome and the performance improvement should be clear from code logic, so just confirm the notifications still work as intended for groups (which is covered by unit tests). For completeness I've included modified testing instructions from MDL-79718 : Test that group notifications still work as intended Log in as a teacher. Create a course and enrol a student (student1). Create a new group (group1) Assign student1 to a group (group1) Create a quiz with an open date one day from now (48 is the threshold). Go to the quiz. Go to More->Overrides. Add a group override for group1 and set the 'Open the quiz' date one week from now. Run this scheduled task to queue the open notification task: php admin/cli/scheduled_task.php --execute=\\mod_quiz\\task\\queue_all_quiz_open_notification_tasks Run adhoc tasks: php admin/cli/adhoc_task.php -e Log in as student1 CONFIRM that you do not have a new notification for the quiz opening. Log in as the teacher Adjust the override date for the group to one hour from now. Run the scheduled task again (see above). Run cron (see above). Log in as student1 CONFIRM that you have a new notification for the quiz opening.
    • Hide

      Code verified against automated checks.

      Checked MDL-85764 using repository: https://github.com/bwalkerl/moodle

      More information about this report

      Built on: Fri Jun 13 04:38:44 UTC 2025

      Show
      Code verified against automated checks. Checked MDL-85764 using repository: https://github.com/bwalkerl/moodle MOODLE_405_STABLE (0 errors / 0 warnings) [branch: MDL-85764-quiz-notification-MOODLE_405_STABLE | CI Job ] MOODLE_500_STABLE (0 errors / 0 warnings) [branch: MDL-85764-quiz-notification-MOODLE_500_STABLE | CI Job ] main (0 errors / 0 warnings) [branch: MDL-85764-quiz-notification | CI Job ] More information about this report Built on: Fri Jun 13 04:38:44 UTC 2025

      We've seen a handful of queue_quiz_open_notification_tasks_for_users adhoc tasks taking multiple hours on a site that has a large amount of users per course and a lot of groups and overrides. One of the examples had over 50 million DB reads, which is excessive for such a simple a task.

      The bottle neck appears to be within groups_is_member() inside update_user_with_date_overrides() - the DB query is being called for every override for every user, which really adds up when a course has thousands of users and overrides.

      This should really be loaded into memory instead if possible.

       

            benjaminwalker Benjamin Walker
            benjaminwalker Benjamin Walker
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

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