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

Tables generate hidden empty rows impacting page size and load time

    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE, MOODLE_500_STABLE
    • MDL-81519-main
    • Hide

      Without the patch applied

      1. Create a course with a quiz with at least one question and enrol a student in to the course
        1. It's a good idea to add a few teachers in the course too
      2. As the student attempt the quiz
      3. As the site admin navigate to the quiz from 1. and click the "Results" tab
      4. Set the value of the "Page size" field (under "Display options") to 120 then press the"Show report" button to save it
      5. As the teachers, set various values for the same field in the report; use values lower than 100 and take note of them (be sure to pick some "funny" (non-round) values like 37 or 83)

      With the patch applied

      1. Run php admin/cli/upgrade.php
      2. As the admin, visit the results tab of the quiz and verify that the "Page size" field is now a drop down, and the value is 100
      3. Still as the admin, right click on the drop down and use your browser's DOM inspector to change the value of the selected value to 120
      4. Press "Show report"
      5. Verify an error is displayed on the "Page size" form element: "Report page size must be between 1 and 100"
      6. As the teachers, visit the results tab of the quiz and verify that the "Page size" field has been rounded up to the nearest 10 (e.g., if you entered 42 before the patch, the value should now be 50)
      7. Press the "Show report" button
      8. Inspect the table using your browser's DOM inspector
      9. Verify there are no invisible empty rows in the table
      10. Repeat the testing instructions from MDL-36011
      Show
      Without the patch applied Create a course with a quiz with at least one question and enrol a student in to the course It's a good idea to add a few teachers in the course too As the student attempt the quiz As the site admin navigate to the quiz from 1. and click the "Results" tab Set the value of the "Page size" field (under "Display options") to 120 then press the"Show report" button to save it As the teachers, set various values for the same field in the report; use values lower than 100 and take note of them (be sure to pick some "funny" (non-round) values like 37 or 83) With the patch applied Run php admin/cli/upgrade.php As the admin, visit the results tab of the quiz and verify that the "Page size" field is now a drop down, and the value is 100 Still as the admin, right click on the drop down and use your browser's DOM inspector to change the value of the selected value to 120 Press "Show report" Verify an error is displayed on the "Page size" form element: "Report page size must be between 1 and 100" As the teachers, visit the results tab of the quiz and verify that the "Page size" field has been rounded up to the nearest 10 (e.g., if you entered 42 before the patch, the value should now be 50) Press the "Show report" button Inspect the table using your browser's DOM inspector Verify there are no invisible empty rows in the table Repeat the testing instructions from MDL-36011
    • Hide

      Code verified against automated checks.

      Checked MDL-81519 using repository: https://github.com/cameron1729/moodle.git

      More information about this report

      Built on: Wed Jun 11 10:02:10 UTC 2025

      Show
      Code verified against automated checks. Checked MDL-81519 using repository: https://github.com/cameron1729/moodle.git main (0 errors / 0 warnings) [branch: MDL-81519-main | CI Job ] More information about this report Built on: Wed Jun 11 10:02:10 UTC 2025
    • Show
      Launching automatic jobs for branch MDL-81519 -main https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/19689/ PHPUnit (sqlsrv / complete) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/67323/ Behat (NonJS - boost and classic / complete) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/67324/ Behat (Firefox - boost / complete) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/67325/ Behat (Firefox - classic / complete) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/67326/ App tests (stable app version) / complete) Built on: Fri Jun 13 05:15:32 UTC 2025

      MDL-36011 added some unusual code where it produces empty rows until the number of rows in the table is equal to the desired page size which can be seen here.

      In certain situations, the user can make the page size any number they want. For example one million. This can result in a ridiculous amount of markup being generated for no good reason and can bring down the webserver.

      To see this:

      1. Create a course with a quiz with a single question and enrol a student
      2. As the student, attempt the quiz
      3. As the admin browse to the quiz and press the "Results" tab
      4. Under "Display options" set "Page size" to 1000000
      5. Press "Show report"
      6. Boom

      The page will take forever to load, and using the network inspector you will see that a ridiculous amount of data is being transferred for a table that has only one meaningful row.

      This exact thing happened to us when an academic accidentally pasted a student number in to that field. This resulted in almost 500mb of useless markup being generated and sent to the browser.

      There are two issues here:

      1. It should not be possible to put such a huge number in that field, instead it should probably be a dropdown with sensible values like 25, 50, 100
      2. The finish_html method shouldn't produce empty rows

      For 2, MDL-36011 seems to indicate it was done because when the headers are printed, it's not known how many total rows of data there will be. So to make the number of rows known at the time headers are printed, it was decided to just print as many rows as the specified page size. I guess what is being referred to in MDL-36011 is this part where the show/hide link needs to specify what it is controlling (the rows in this case). However there is actually enough information present at the time the table headers are printed to know the exact row count, so this hack/workaround was never needed in the first place and instead the correct number of rows should have been calculated.

      Original issue description

      Changing the display option "page size" on quiz reports has a big impact on page size and load time.
      For example on a quiz with one student and one attempt, with the default page size of 30 the response request is ~300kB
      On the same quiz, if you change the page size to 30000 the page size is then 25.35MB
      The page takes also longer to load.
      It seems weird to have a bigger page when the actual data is unchanged.

      Step to reproduce:

      • As a teacher
      • Create a quiz
      • Add a question to that quiz
      • As a student
      • Make an attempt on the quiz
      • As a teacher
      • go to the "Results" page of the quiz
      • keep the "page size" at 30 and "Show report"
      • check the browser's console network tab to see page size
      • change "page size" to 3000 and show report
      • check the browser's console again and notice that the page size is bigger

      This size difference is because for some reason Moodle is creating rows in the result table based on the "page size" parameter value instead of the actual DB results.
      The extra rows have the class `emptyrow` that makes them hidden but they are still in the DOM for no reason

            cameron1729 cameron1729
            benjamin-unige Benjamin-unige
            Jose Pico Jose Pico
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 minute
                1m

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