
Bug

Resolution: Fixed

Major

4.0.3, 4.0.6, 4.1.1, 4.1.2
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 statsrelated 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:
 (Cleaned up some incorrect PHPdoc comments.)
 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 bulkloaded values.
 Also, I have changed the policy, we no longer try to compute statistics onthefly 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.
 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.
 Also, previously computed statistics were previously only used for up to 15 minutes, then ignored. That is no longer the case.
 Some of the old code has been deprecated, masteronly.
 caused a regression

MDL78488 Question bank statistics still being pulled/loaded when associated columns disabled
 Closed

MDL78327 Random PHPUnit failures related to question statistics after MDL75576
 Closed

MDL78580 Add locking to quiz statistics calculation to prevent database deadlocks
 Closed

MDL78588 Question bank statistics: computing something, when it should only be using cached values
 Closed

MDL78608 Question bank must be robust if question_usages are not cleaned up when a context is deleted
 Closed
 Discovered while testing

MDL74762 Statistics in the Moodle 4.0 question bank use many DB queries causing performance problems
 Closed
 has a nonspecific relationship to

MDL78336 'Needs checking?', 'Facility index' and 'Discriminative efficiency' columns are still showing no data
 Closed
 has been marked as being related by

MDL77080 Exceptions when running Recalculate question statistics scheduled task
 Closed

MDL77094 Quiz statistics scheduled task: fix more obvious inefficiencies
 Closed

MDL78090 Moodle 4.7 core_question final deprecations
 Open

MDL78091 Moodle 4.7 quiz final deprecations
 Open
 is a regression caused by

MDL74762 Statistics in the Moodle 4.0 question bank use many DB queries causing performance problems
 Closed
 is duplicated by

MDL77836 Duplicated records with question bank statistics
 Open

MDL76832 Timeout when toggling between question bank categories
 Closed

MDL77867 question_stats_cleanup_task fails with "number of parameters must be between 0 and 65535"
 Closed