Project: moodle
Issue MDL-41726: Serious performance regression in course reset of groups, including race condition that may send erroneous emails to students
Steps to reproduce # Create a large course, say with 10,000 users, a few dozen groups each with a few thousand members, and several quizzes. (The OU has courses this big.) # Time doing a course reset to remove all group members. (Also look at the DB query count in the footer.) Do this for Moodle versions both before and after MDL-39958 was integrated. (Note that MDL-39958 was committed with MDL-39959 is the issue id in the commit comment.) That is the perofrmance problem. Now the nasty race condition. # Work out which order $DB->get_recordset('groups', array('courseid' => $courseid)); in groups_delete_group_members, in particular identify which goup will be deleted first, and which last. # For one quiz, set Time limits as follows: #* Quiz closes: Now + 1 day #* Quiz closes group override for last group to be processed: Now - 1 day #* Quiz closes group override for first group to be processed: Now + 1 day # Set the quiz to have attempts become overdue when time expires, and to send an email notification to student when this happens. # Start an attempt as one student that is a member of both those groups. Answer some questions but don't submit. # Now, try to work out when cron will next run, and just beofre that, do a course reset to remove all the group members, Now also need to be between T + 1 minute and T + 1 day. Expected result: The student does not get a notification, because initially the close date is Now + 1 day, and when they are removed from both groups it is Now + 1 day. Possible result: Cron runs between time the student is removed from the first group, and the time they are removed from the last group. Hence cron sees them as due to submit T - 1 day ago, and so makes their attempt overdue, and sends them an incorrect email.
Story points: 100