From 4699b8bc4132e535dc5d30de9d9f6839fca18b65 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 26 Oct 2018 14:53:58 +0800 Subject: [PATCH] Revert "MDL-63466 core_message: removed get_last_message_time_created_cache_key" This reverts commit 4f22d7f23b022c143910a9a136fecbd325dce356. --- lib/messagelib.php | 3 ++- message/classes/api.php | 8 +++++--- message/classes/helper.php | 10 ++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/messagelib.php b/lib/messagelib.php index 3fcaa94c6ea..deca4e615d7 100644 --- a/lib/messagelib.php +++ b/lib/messagelib.php @@ -295,7 +295,8 @@ function message_send(\core\message\message $eventdata) { if (!empty($eventdata->convid)) { // Cache the timecreated value of the last message in this conversation. $cache = cache::make('core', 'message_time_last_message_in_conversation'); - $cache->set($eventdata->convid, $tabledata->timecreated); + $key = \core_message\helper::get_last_message_time_created_cache_key($eventdata->convid); + $cache->set($key, $tabledata->timecreated); } } diff --git a/message/classes/api.php b/message/classes/api.php index 78e596834b4..57619cff7c0 100644 --- a/message/classes/api.php +++ b/message/classes/api.php @@ -630,8 +630,9 @@ class api { } // Check the cache to see if we even need to do a DB query. - $cache = \cache::make('core', 'message_time_last_message_in_conversation'); - $lastcreated = $cache->get($conversationid); + $cache = \cache::make('core', 'message_time_last_message_between_users'); + $key = helper::get_last_message_time_created_cache_key($conversationid); + $lastcreated = $cache->get($key); // The last known message time is earlier than the one being requested so we can // just return an empty result set rather than having to query the DB. @@ -667,7 +668,8 @@ class api { if (!empty($timefrom)) { // Check the cache to see if we even need to do a DB query. $cache = \cache::make('core', 'message_time_last_message_in_conversation'); - $lastcreated = $cache->get($convid); + $key = helper::get_last_message_time_created_cache_key($convid); + $lastcreated = $cache->get($key); // The last known message time is earlier than the one being requested so we can // just return an empty result set rather than having to query the DB. diff --git a/message/classes/helper.php b/message/classes/helper.php index 89619f89191..3b090757de0 100644 --- a/message/classes/helper.php +++ b/message/classes/helper.php @@ -440,6 +440,16 @@ class helper { return sha1(implode('-', $userids)); } + /** + * Returns the cache key for the time created value of the last message of this conversation. + * + * @param int $convid The conversation identifier. + * @return string The key. + */ + public static function get_last_message_time_created_cache_key(int $convid) { + return $convid; + } + /** * Checks if legacy messages exist for a given user. *