MDL-75576 quiz statistics: don't compute when a user views the qbank

Previously, when users viewed the question bank, if the quiz statistics
had not already been calculated, we would try to compute them there an then.
This could be very, very slow, leading to session lock problems.

Now, we never try to compute the statistics on the fly. Instead, we rely
on the existing \quiz_statistics\task\recalculate scheduled task to do it.
This commit is contained in:
Tim Hunt 2023-01-30 16:02:50 +00:00
parent bc7dacecb6
commit b112cee58c
6 changed files with 44 additions and 6 deletions

View file

@ -72,6 +72,7 @@ Feature: Show statistics in question bank
| slot | response |
| 1 | True |
| 2 | True |
And I run the scheduled task "\quiz_statistics\task\recalculate"
When I am on the "Course 1" "core_question > course question bank" page logged in as "admin"
Then I should see "50.00%" in the "TF1" "table_row"
And I should see "75.00%" in the "TF2" "table_row"
@ -87,6 +88,7 @@ Feature: Show statistics in question bank
| slot | response |
| 1 | True |
| 2 | True |
And I run the scheduled task "\quiz_statistics\task\recalculate"
When I am on the "Course 1" "core_question > course question bank" page logged in as "admin"
Then I should see "50.00%" in the "TF1" "table_row"
And I should see "75.00%" in the "TF2" "table_row"
@ -102,6 +104,7 @@ Feature: Show statistics in question bank
| slot | response |
| 1 | True |
| 2 | True |
And I run the scheduled task "\quiz_statistics\task\recalculate"
When I am on the "Course 1" "core_question > course question bank" page logged in as "admin"
Then I should see "Likely" in the "TF1" "table_row"
And I should see "Unlikely" in the "TF2" "table_row"
@ -123,6 +126,7 @@ Feature: Show statistics in question bank
| slot | response |
| 1 | True |
| 2 | False |
And I run the scheduled task "\quiz_statistics\task\recalculate"
When I am on the "Course 1" "core_question > course question bank" page logged in as "admin"
Then I should see "Likely" in the "TF1" "table_row"
And I should see "Very likely" in the "TF2" "table_row"

View file

@ -225,6 +225,12 @@ class helper_test extends \advanced_testcase {
foreach ($quiz2attempts as $attempt) {
$this->submit_quiz($quiz2, $attempt);
}
// Calculate the statistics.
$this->expectOutputRegex('~.*Calculations completed.*~');
$statisticstask = new \quiz_statistics\task\recalculate();
$statisticstask->execute();
return [$quiz1, $quiz2, $questions];
}

View file

@ -232,6 +232,12 @@ class statistics_bulk_loader_test extends advanced_testcase {
foreach ($quiz2attempts as $attempt) {
$this->submit_quiz($quiz2, $attempt);
}
// Calculate the statistics.
$this->expectOutputRegex('~.*Calculations completed.*~');
$statisticstask = new \quiz_statistics\task\recalculate();
$statisticstask->execute();
return [$quiz1, $quiz2, $questions];
}