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

Make regrading of course final grades asynchronous

XMLWordPrintable

    • MOODLE_402_STABLE, MOODLE_403_STABLE, MOODLE_404_STABLE, MOODLE_500_STABLE
    • MOODLE_500_STABLE
    • MDL-81714_main
    • Hide

      You will need to have access to save and run CLI scripts in your Moodle installation.

      1 In your Moodle, log in as admin, go to Site administration / Development / Make test course and create a medium (M) sized course with your preferred short name and full name.
      2 In the test courses, users do not have grades, so we will create some. Save the file creategrades.php (attached to this issue) into the root directory of your Moodle installation.
      3 Run it with php creategrades.php 1234 where 1234 is the course id of your medium test course. This script will create random grades for all users on all 100 assignments on the course, but you don't need to wait for it to do that (which will take several hours). Just wait until it says Assignment 1: done (which should be less than 5 minutes) then press Ctrl+C to exit the script.

      4 Back in your medium course, turn editing on and click Add an activity or resource and then choose Quiz.
      5 Type in a name for the quiz, but make no other changes (don't save yet)
      6 Click Save and display

      • You should be taken straight to the quiz activity with no delay.

      7 Go to the Grader report for the course.

      • You should see a progress bar at the top of the screen, with the text "Grade recalculations are being performed in the background. Displayed grades may be incorrect until the process is complete."
      • You should see a "Run now" button displayed below the progress bar.

      8 Go to Site Administration > Server > Adhoc Tasks

      • Confirm there is a pending instance of \core_course\task\regrade_final_grades.

      9 Run the pending \core_course\task\regrade_final_grades task (via the cron, adhoc_task.php CLI script, the link on the Adhoc tasks page, or the "Run now" button).

      10 Watch the progress bar on the Grader report page.

      • It should be updated as the task runs to completion.
      • Once the progress starts, the "Run now" button should be removed.

      11 Reload the page.

      • The message an progress bar should no longer be displayed.

      12 Assign one of the course participants the Teacher role, log out and log in as that user.

      13. Repeat steps 4-7.

      • The result should be the same, except that the "Run now" button that was visible to admin should not be displayed to the teacher.
      Show
      You will need to have access to save and run CLI scripts in your Moodle installation. 1 In your Moodle, log in as admin, go to Site administration / Development / Make test course and create a medium ( M ) sized course with your preferred short name and full name. 2 In the test courses, users do not have grades, so we will create some. Save the file creategrades.php (attached to this issue) into the root directory of your Moodle installation. 3 Run it with php creategrades.php 1234 where 1234 is the course id of your medium test course. This script will create random grades for all users on all 100 assignments on the course, but you don't need to wait for it to do that (which will take several hours). Just wait until it says Assignment 1: done (which should be less than 5 minutes) then press Ctrl+C to exit the script. 4 Back in your medium course, turn editing on and click Add an activity or resource and then choose Quiz . 5 Type in a name for the quiz, but make no other changes (don't save yet) 6 Click Save and display You should be taken straight to the quiz activity with no delay. 7 Go to the Grader report for the course. You should see a progress bar at the top of the screen, with the text "Grade recalculations are being performed in the background. Displayed grades may be incorrect until the process is complete." You should see a "Run now" button displayed below the progress bar. 8 Go to Site Administration > Server > Adhoc Tasks Confirm there is a pending instance of \core_course\task\regrade_final_grades. 9 Run the pending \core_course\task\regrade_final_grades task (via the cron, adhoc_task.php CLI script, the link on the Adhoc tasks page, or the "Run now" button). 10 Watch the progress bar on the Grader report page. It should be updated as the task runs to completion. Once the progress starts, the "Run now" button should be removed. 11 Reload the page. The message an progress bar should no longer be displayed. 12 Assign one of the course participants the Teacher role, log out and log in as that user. 13. Repeat steps 4-7. The result should be the same, except that the "Run now" button that was visible to admin should not be displayed to the teacher.
    • Show
      Fails against automated checks. Checked MDL-81714 using repository: https://github.com/marxjohnson/moodle main (1 errors / 5 warnings) [branch: MDL-81714_main | CI Job ] overview (0/0) , phplint (0/0) , phpcs (1/0) , js (0/0) , css (0/0) , phpdoc (0/0) , commit (0/1) , savepoint (0/0) , thirdparty (0/0) , externalbackup (0/0) , grunt (0/0) , shifter (0/0) , mustache (0/4) , gherkin (0/0) , Should these errors be fixed? Built on: Mon Mar 17 10:40:13 UTC 2025
    • Show
      Launching automatic jobs for branch MDL-81714 _main https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/18626/ PHPUnit (sqlsrv / complete) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/63777/ Behat (NonJS - boost and classic / complete) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/63778/ Behat (Firefox - boost / complete) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/63779/ Behat (Firefox - classic / complete) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/63780/ App tests (stable app version) / complete) Built on: Mon Mar 17 13:04:08 UTC 2025

      Since MDL-75878, We have been seeing teachers in very large courses (students x activities) having to wait a very long time for the regrading of final grades to take place before they can perform any other action in Moodle - this is usually triggered after creating an activity like a quiz - but cannot start editing the quiz until the course level recalculations have been completed, other users are unaffected and can keep navigating the course . 

       

      We should move the processing into an ad-hoc task and free the teachers to keep editing the course.

       

       

      We have developed a patch for this which has made a significant performance impact:

      Before:

      • ~ 3.5 minutes for regrade to complete and then next page is instant.

      After:

      • by using "Save and display" - ~6.75s
      • by using "Save and return to course" - ~19s

      I'm guessing return to course is slower because it'll hit the coursemodinfo partial rebuild lock, but overall massive difference

      Reproduction steps

      You will need to have access to save and run CLI scripts in your Moodle installation.

      1 In your Moodle, go to Site administration / Development / Make test course and create a medium (M) sized course with your preferred short name and full name.
      2 In the test courses, users do not have grades, so we will create some. Save the file creategrades.php (attached to this issue) into the root directory of your Moodle installation.
      3 Run it with php creategrades.php 1234 where 1234 is the course id of your medium test course. This script will create random grades for all users on all 100 assignments on the course, but you don't need to wait for it to do that (which will take several hours). Just wait until it says Assignment 1: done (which should be less than 5 minutes) then press Ctrl+C to exit the script.

      • For some reason I don't understand, this is actually enough to fill in blank grades for all the assignments, so it has the full performance impact just like running it for all of them.

      4 Back in your medium course, turn editing on and click Add an activity or resource and then choose Quiz.
      5 Type in a name for the quiz, but make no other changes (don't save yet)
      6 Click Save and display

      • You should be taken to another page with heading Recalculating grades and a progress bar. (Depending on the configuration of your web server, the page might not actually appear before the progress bar finishes.)
      • This process will take about 30s in this scenario. As described above, it can take several minutes on large complex courses.

      7 Click Continue

      • You should get to the quiz activity.

        1. A recalculating pending.png
          A recalculating pending.png
          64 kB
        2. B recalculating pending.png
          B recalculating pending.png
          64 kB
        3. creategrades.php
          1 kB
        4. C recalculation in progress.png
          C recalculation in progress.png
          67 kB
        5. MDL-81714.png
          MDL-81714.png
          218 kB
        6. MDL-81714-1.png
          MDL-81714-1.png
          555 kB
        7. Recalculating in progress.png
          Recalculating in progress.png
          212 kB
        8. regradeinprogress.png
          regradeinprogress.png
          28 kB
        9. regradeinprogress2.png
          regradeinprogress2.png
          25 kB
        10. regreaderunnow.png
          regreaderunnow.png
          25 kB
        11. Screenshot 2024-11-13 at 14.37.39.png
          Screenshot 2024-11-13 at 14.37.39.png
          64 kB
        12. Styling reference.png
          Styling reference.png
          234 kB
        13. Timer.svg
          1 kB

            marxjohnson Mark Johnson
            aspark Alistair Spark
            Simon Adams Simon Adams
            Jun Pataleta Jun Pataleta
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            2 Vote for this issue
            Watchers:
            18 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 week, 2 days, 5 hours, 48 minutes
                1w 2d 5h 48m

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