MDL-68440 cache: Added counting of default mappings

This commit is contained in:
Peter Burnett 2020-04-21 10:00:35 +10:00
parent 46f977a8bf
commit 3d49421a21
2 changed files with 25 additions and 2 deletions

View File

@ -101,13 +101,31 @@ abstract class administration_helper extends cache_helper {
ksort($default);
$return = $return + $default;
foreach ($instance->get_definition_mappings() as $mapping) {
$mappings = $instance->get_definition_mappings();
foreach ($mappings as $mapping) {
if (!array_key_exists($mapping['store'], $return)) {
continue;
}
$return[$mapping['store']]['mappings']++;
}
// Now get all definitions, and if not mapped, increment the defaults for the mode.
$modemappings = $instance->get_mode_mappings();
foreach ($instance->get_definitions() as $definition) {
// Construct the definition name to search for.
$defname = $definition['component'] . '/' . $definition['area'];
// Skip if definition is already mapped.
if (array_search($defname, array_column($mappings, 'definition')) !== false) {
continue;
}
$mode = $definition['mode'];
// Get the store name of the default mapping from the mode.
$index = array_search($mode, array_column($modemappings, 'mode'));
$store = $modemappings[$index]['store'];
$return[$store]['mappings']++;
}
return $return;
}

View File

@ -92,7 +92,12 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
$this->assertEquals(0, $summary['default']);
$this->assertEquals(1, $summary['isready']);
$this->assertEquals(1, $summary['requirementsmet']);
$this->assertEquals(1, $summary['mappings']);
// Find the number of mappings to sessionstore.
$mappingcount = count(array_filter($config->get_definitions(), function($element) {
return $element['mode'] === cache_store::MODE_APPLICATION;
}));
$this->assertEquals($mappingcount, $summary['mappings']);
$definitionsummaries = core_cache\administration_helper::get_definition_summaries();
$this->assertInternalType('array', $definitionsummaries);