Skip to content

Commit

Permalink
MDL-68440 cache: Added counting of default mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
Peterburnett committed Oct 12, 2020
1 parent 46f977a commit 3d49421
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 19 additions & 1 deletion cache/classes/administration_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,31 @@ public static function get_store_instance_summaries(): array {
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;
}

Expand Down
7 changes: 6 additions & 1 deletion cache/tests/administration_helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ public function test_get_summaries() {
$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);
Expand Down

0 comments on commit 3d49421

Please sign in to comment.