When upgrading from MDL 2.6 to MDL 2.7 > MDL 3.1, SCORM behaviour changes when exiting activity. We suspect it is due to the changes in logs to event type logs between 2.6 and 2.7.
After investigation the following is true:
:black_small_square: there are a lot of requests to DB and calculations related somewhere between grades, students and events.
:black_small_square: for some reason Moodle also includes other users in this process.
:black_small_square: our upgraded site has around 63000 users and 1.500.000 records in grade_grades table in DB
Here is the trace in 2.6:
mod/scorm/datamodel.php line 80 $valid = scorm_seq_overall ($scoid, $USER->id, $action, $attempt);
mod/scorm/locallib.php line 544 scorm_update_grades($scorm, $userid);
mod/scorm/lib.php line 620 scorm_grade_item_update($scorm, $grades);
mod/scorm/lib.php line 675 return grade_update('mod/scorm', $scorm->course, 'mod', 'scorm', $scorm->id, 0, $grades, $params);
lib/gradelib.php line 130 else statement is executed every few seconds (3-8)
line 234 $grade_grade = new grade_grade($gd, false); is executed around 200.000 times. All users are in query.
//This last line is added in 2.7 and is not present in 2.6, which when executed takes a long time especially when many users and grades are stored in DB
line 1953 \core\event\user_graded::create_from_grade($grade)->trigger(); Takes about 10 seconds to execute.