Merge branch 'MDL-78297-master' of https://github.com/MartinGauk/moodle

This commit is contained in:
Andrew Nicols 2023-06-12 10:17:13 +08:00
commit a677a02d71
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
3 changed files with 11 additions and 24 deletions

View File

@ -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';

View File

@ -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'];

View File

@ -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.
),