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

Question bank statistics are fetched in a terribly inefficient way

    XMLWordPrintable

Details

    • MOODLE_400_STABLE, MOODLE_401_STABLE
    • MOODLE_400_STABLE, MOODLE_401_STABLE, MOODLE_402_STABLE
    • MDL-75576_401
    • MDL-75576_402
    • Hide

      The work-around is to disable the qbank_statistics plugin on Admin -> Plugins -> Question bank plugins -> Manage question bank plugins.

      Show
      The work-around is to disable the qbank_statistics plugin on Admin -> Plugins -> Question bank plugins -> Manage question bank plugins.
    • Hide

      Mostly, there should be no user-visibile changes (other than a really noticable speed-up on large Moodle sites.)

      The one different behaviour is that now, question statistics are only shown if they have aready been computed by the scheduled task. If you want to test this: (actually, I don't think it is worth a human doing this, but I will still write it out, becuase I think it makes the new behaviour clear.

      Requires: the ability to Run now a scheduled task.

      1. Log in as admin.
      2. Go to Admin -> Server -> Tasks -> sheduled tasks.
      3. Disable the \quiz_statistics\task\recalculate task.
      4. Create a course.
      5. Create a quiz.
      6. Add a single true-false question to the quiz.
      7. Log in as a student.
      8. Attempt the quiz, getting the question right, and submitting the attempt.
      9. Log in as admin.
      10. Go to the course.
      11. Go to More -> Question bank.
      12. Note that the 'Facility index' contains N/A. (Not sure N/a is the most
      13. Go to Admin -> Server -> Tasks -> sheduled tasks.
      14. Click Run now for the \quiz_statistics\task\recalculate task (or enable it, and wait for Cron to run it.)
      15. Go to the course question bank.
      16. Note that the Facility index for the true-false question is now shown as 100%.
      17. Wait at least 15 minutes (sorry), then reload the question bank and ensure the statistics are still shown.
      Show
      Mostly, there should be no user-visibile changes (other than a really noticable speed-up on large Moodle sites.) The one different behaviour is that now, question statistics are only shown if they have aready been computed by the scheduled task. If you want to test this: (actually, I don't think it is worth a human doing this, but I will still write it out, becuase I think it makes the new behaviour clear. Requires: the ability to Run now a scheduled task. Log in as admin. Go to Admin -> Server -> Tasks -> sheduled tasks. Disable the \quiz_statistics\task\recalculate task. Create a course. Create a quiz. Add a single true-false question to the quiz. Log in as a student. Attempt the quiz, getting the question right, and submitting the attempt. Log in as admin. Go to the course. Go to More -> Question bank. Note that the 'Facility index' contains N/A. (Not sure N/a is the most Go to Admin -> Server -> Tasks -> sheduled tasks. Click Run now for the \quiz_statistics\task\recalculate task (or enable it, and wait for Cron to run it.) Go to the course question bank. Note that the Facility index for the true-false question is now shown as 100%. Wait at least 15 minutes (sorry), then reload the question bank and ensure the statistics are still shown.

    Description

      When the question bank is displayed, there is a loop over the questions (rows) in the display.

      For each row, there is a loop over the columns. Typically three colums display stats-related data.

      So, for each question x 3, we call calculate_average_question_stats_item. This:

      • does a DB query to find in which (component, contextid) combinations the question is used it.
      • Loops over that, and for each combinations, calls the calls a callaback in the component to load the entire blob of statistics (e.g. the stats for all questions in all attempts at a particular quiz) out of that we pick the one statistic for the one question we are interested in using in our average.

      This code is clearly a long way from optimal.

      To fix this, I have done the following:

      1. (Cleaned up some incorrect PHPdoc comments.)
      2. There is now a new mechanism where
        • Question bank columns can declare which statistics they need.
        • core_question\local\bank\view then loads all the statistics required by all columns in one go.
        • and there is a method to then access those bulk-loaded values.
      3. Also, I have changed the policy, we no longer try to compute statistics on-the-fly when a user tries to view the question bank. Now, we only show satistics if quiz_statistics\task\recalculate (or another equivalent task) has already computed them.
      4. Related to this, an old task, deleting statistics data was removed. Instead, now, before computing new data, we delete the previous data with the same settings.
      5. Also, previously computed statistics were previously only used for up to 15 minutes, then ignored. That is no longer the case.
      6. Some of the old code has been deprecated, master-only.

      Attachments

        1. (I) Passed -- (400)MDL-75576.png
          (I) Passed -- (400)MDL-75576.png
          105 kB
        2. (I) Passed -- (401)MDL-75576.png
          (I) Passed -- (401)MDL-75576.png
          120 kB
        3. (I) Passed -- (402)MDL-75576.png
          (I) Passed -- (402)MDL-75576.png
          116 kB
        4. (I) Passed -- (Master)MDL-75576.png
          (I) Passed -- (Master)MDL-75576.png
          124 kB
        5. deadlock.txt
          5 kB
        6. deadlock-1.txt
          5 kB
        7. screenshot-1.png
          screenshot-1.png
          22 kB
        8. screenshot-2.png
          screenshot-2.png
          40 kB

        Issue Links

          Activity

            People

              timhunt Tim Hunt
              timhunt Tim Hunt
              Anupama Sarjoshi Anupama Sarjoshi
              Jun Pataleta Jun Pataleta
              Kim Jared Lucas Kim Jared Lucas
              Votes:
              33 Vote for this issue
              Watchers:
              52 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 2 days, 5 hours, 4 minutes
                  2d 5h 4m

                  Clockify

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