diff --git a/lang/en/cache.php b/lang/en/cache.php index 5d5a275a549..3cbd994cf40 100644 --- a/lang/en/cache.php +++ b/lang/en/cache.php @@ -57,7 +57,6 @@ $string['cachedef_courseeditorstate'] = 'Session course state cache keys to dete $string['cachedef_course_image'] = 'Course images'; $string['cachedef_course_user_dates'] = 'The user dates for courses set to relative dates mode'; $string['cachedef_completion'] = 'Activity completion status'; -$string['cachedef_deprecatedcapabilities'] = 'System deprecated capabilities list'; $string['cachedef_databasemeta'] = 'Database meta information'; $string['cachedef_eventinvalidation'] = 'Event invalidation'; $string['cachedef_externalbadges'] = 'External badges for particular user'; diff --git a/lib/accesslib.php b/lib/accesslib.php index 18673d44900..d5699be6290 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -2608,13 +2608,10 @@ function get_capability_info($capabilityname) { * @return stdClass|null with deprecation message and potential replacement if not null */ function get_deprecated_capability_info($capabilityname) { - // Here if we do like get_all_capabilities, we run into performance issues as the full array is unserialised each time. - // We could have used an adhoc task but this also had performance issue. Last solution was to create a cache using - // the official caches.php file. The performance issue shows in test_permission_evaluation. - $cache = cache::make('core', 'deprecatedcapabilities'); - // Cache has not be initialised. - if (!$cache->get('deprecated_capabilities_initialised')) { - // Look for deprecated capabilities in each components. + $cache = cache::make('core', 'capabilities'); + $alldeprecatedcaps = $cache->get('deprecated_capabilities'); + if ($alldeprecatedcaps === false) { + // Look for deprecated capabilities in each component. $allcaps = get_all_capabilities(); $components = []; $alldeprecatedcaps = []; @@ -2627,18 +2624,19 @@ function get_deprecated_capability_info($capabilityname) { require($defpath); if (!empty($deprecatedcapabilities)) { foreach ($deprecatedcapabilities as $cname => $cdef) { - $cache->set($cname, $cdef); + $alldeprecatedcaps[$cname] = $cdef; } } } } } - $cache->set('deprecated_capabilities_initialised', true); + $cache->set('deprecated_capabilities', $alldeprecatedcaps); } - if (!$cache->has($capabilityname)) { + + if (!isset($alldeprecatedcaps[$capabilityname])) { return null; } - $deprecatedinfo = $cache->get($capabilityname); + $deprecatedinfo = $alldeprecatedcaps[$capabilityname]; $deprecatedinfo['fullmessage'] = "The capability '{$capabilityname}' is deprecated."; if (!empty($deprecatedinfo['message'])) { $deprecatedinfo['fullmessage'] .= $deprecatedinfo['message']; diff --git a/lib/db/caches.php b/lib/db/caches.php index e4c67e08ca2..eb9ccdc7ea1 100644 --- a/lib/db/caches.php +++ b/lib/db/caches.php @@ -160,23 +160,13 @@ $definitions = array( 'ttl' => 900, ), - // Cache the capabilities list DB table. See get_all_capabilities in accesslib. + // Cache the capabilities list DB table. See get_all_capabilities and get_deprecated_capability_info in accesslib. 'capabilities' => array( 'mode' => cache_store::MODE_APPLICATION, 'simplekeys' => true, 'simpledata' => true, 'staticacceleration' => true, - 'staticaccelerationsize' => 1, - 'ttl' => 3600, // Just in case. - ), - - // Cache the deprecated capabilities list. See get_deprecated_capability_info in accesslib. - 'deprecatedcapabilities' => array( - 'mode' => cache_store::MODE_APPLICATION, - 'simplekeys' => false, // We need to hash the key. - 'simpledata' => true, - 'staticacceleration' => true, - 'staticaccelerationsize' => 1, + 'staticaccelerationsize' => 2, // Should be main capabilities and deprecated capabilities. 'ttl' => 3600, // Just in case. ),