From a3ba4772a57dd33fc1a97ab3d1e7a765a020869c 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. --- mod/quiz/report/statistics/classes/calculator.php | 15 +++++---------- mod/quiz/report/statistics/upgrade.txt | 5 +++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mod/quiz/report/statistics/classes/calculator.php b/mod/quiz/report/statistics/classes/calculator.php index e6ff9567a69..8cd5620522a 100644 --- a/mod/quiz/report/statistics/classes/calculator.php +++ b/mod/quiz/report/statistics/classes/calculator.php @@ -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()]); } /** diff --git a/mod/quiz/report/statistics/upgrade.txt b/mod/quiz/report/statistics/upgrade.txt index 66ef390739e..a85da1b8984 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. The constant calculator::TIME_TO_CACHE will be + deprecated in Moodle 4.3. + === 3.2 ===