From 7994f1c9858dec731ae2a5b849635b08d75d673d Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Fri, 17 Feb 2023 15:53:55 +0000 Subject: [PATCH] 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. --- .../report/statistics/classes/calculator.php | 19 +++++++++---------- mod/quiz/report/statistics/upgrade.txt | 5 +++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/mod/quiz/report/statistics/classes/calculator.php b/mod/quiz/report/statistics/classes/calculator.php index 514669e7087..bc5fe65af7d 100644 --- a/mod/quiz/report/statistics/classes/calculator.php +++ b/mod/quiz/report/statistics/classes/calculator.php @@ -121,21 +121,23 @@ class calculator { return $quizstats; } - /** @var integer Time after which statistics are automatically recomputed. */ + /** + * @var int Time after which statistics are automatically recomputed. + * @deprecated since Moodle 4.3. Use of pre-computed stats is no longer time-limited. + * @todo MDL-78091 Final deprecation in Moodle 4.7 + */ 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 > ?', - [$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 +147,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 > ?', - [$qubaids->get_hash_code(), $timemodified]); + return $DB->get_field('quiz_statistics', 'timemodified', ['hashcode' => $qubaids->get_hash_code()]); } /** diff --git a/mod/quiz/report/statistics/upgrade.txt b/mod/quiz/report/statistics/upgrade.txt index 0714629032f..415263c1e10 100644 --- a/mod/quiz/report/statistics/upgrade.txt +++ b/mod/quiz/report/statistics/upgrade.txt @@ -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. Therefore, the constant calculator::TIME_TO_CACHE has been + deprecated. + === 3.2 ===