MDL-75576 quiz statistics: don't time-limit the use of cached values

This should have been done as part of  MDL-74762, but was missed.
This commit is contained in:
Tim Hunt 2023-02-17 15:53:55 +00:00
parent 86932a330b
commit a532f407bb
2 changed files with 10 additions and 10 deletions

View File

@ -121,21 +121,19 @@ class calculator {
return $quizstats;
}
/** @var integer Time after which statistics are automatically recomputed. */
/** @var int No longer used. Previously the time after which statistics are automatically recomputed. */
const TIME_TO_CACHE = 900; // 15 minutes.
/**
* Load cached statistics from the database.
*
* @param $qubaids \qubaid_condition
* @param \qubaid_condition $qubaids
* @return calculated The statistics for overall attempt scores or false if not cached.
*/
public function get_cached($qubaids) {
global $DB;
$timemodified = time() - self::TIME_TO_CACHE;
$fromdb = $DB->get_record_select('quiz_statistics', 'hashcode = ? AND timemodified > ?',
array($qubaids->get_hash_code(), $timemodified));
$fromdb = $DB->get_record('quiz_statistics', ['hashcode' => $qubaids->get_hash_code()]);
$stats = new calculated();
$stats->populate_from_record($fromdb);
return $stats;
@ -145,14 +143,11 @@ class calculator {
* Find time of non-expired statistics in the database.
*
* @param $qubaids \qubaid_condition
* @return integer|boolean Time of cached record that matches this qubaid_condition or false is non found.
* @return int|bool Time of cached record that matches this qubaid_condition or false is non found.
*/
public function get_last_calculated_time($qubaids) {
global $DB;
$timemodified = time() - self::TIME_TO_CACHE;
return $DB->get_field_select('quiz_statistics', 'timemodified', 'hashcode = ? AND timemodified > ?',
array($qubaids->get_hash_code(), $timemodified));
return $DB->get_field('quiz_statistics', 'timemodified', ['hashcode' => $qubaids->get_hash_code()]);
}
/**

View File

@ -7,6 +7,11 @@ information provided here is intended especially for developers.
(which are really private to the quiz, and not part of any API you should be using) now have a new
optional argument $calculateifrequired.
* In the past, the methods \quiz_statistics\calculator::get_last_calculated_time() and calculator::get_cached()
only returned the pre-computed statistics if they were computed less than 15 minutes ago. Now, they will
always return any computed statistics that exist. The constant calculator::TIME_TO_CACHE will be
deprecated in Moodle 4.2.
=== 3.2 ===