From 2cc3588b7778d9b589d98cefeaaa3949be366329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Tue, 15 Sep 2020 10:19:46 +0200 Subject: [PATCH 1/2] MDL-69698 licenses: Do not cache the localised licenses fullnames The localisation must happen only after loading the list of licenses from cache so that the name is displayed in the current user's preferred language, not in the language of the user who initiated the cache rebuild. --- lib/licenselib.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/licenselib.php b/lib/licenselib.php index 3010ef9b2dd..c12bc54c113 100644 --- a/lib/licenselib.php +++ b/lib/licenselib.php @@ -227,21 +227,24 @@ class license_manager { $cache = \cache::make('core', 'license'); $licenses = $cache->get('licenses'); - if (empty($licenses)) { + if ($licenses === false) { $licenses = []; $records = $DB->get_records_select('license', null, null, 'sortorder ASC'); foreach ($records as $license) { - // Interpret core license strings for internationalisation. - if ($license->custom == self::CORE_LICENSE) { - $license->fullname = get_string($license->shortname, 'license'); - } else { - $license->fullname = format_string($license->fullname); - } $licenses[$license->shortname] = $license; } $cache->set('licenses', $licenses); } + foreach ($licenses as $license) { + // Localise the license names. + if ($license->custom == self::CORE_LICENSE) { + $license->fullname = get_string($license->shortname, 'core_license'); + } else { + $license->fullname = format_string($license->fullname); + } + } + return $licenses; } From 91ae4ab5db72df10f9a3cf5194b849e8ad6b034e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Tue, 15 Sep 2020 10:22:57 +0200 Subject: [PATCH 2/2] MDL-69698 licenses: Improve the performance of the licenses cache The cache uses a single simple key and there is no need to hash it. --- lib/db/caches.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/db/caches.php b/lib/db/caches.php index 14dca042857..b05d07977e3 100644 --- a/lib/db/caches.php +++ b/lib/db/caches.php @@ -466,7 +466,7 @@ $definitions = array( // Cache for licenses. 'license' => [ 'mode' => cache_store::MODE_APPLICATION, - 'simplekeys' => false, - 'simpledata' => false + 'simplekeys' => true, + 'simpledata' => false, ], );