Skip to content

Commit

Permalink
Remove wasteful double-caching of settings metadata
Browse files Browse the repository at this point in the history
Settings metadata was being cached once per domain and one extra time for good measure.
  • Loading branch information
colemanw committed May 16, 2019
1 parent 405192f commit 9d9d98f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
22 changes: 5 additions & 17 deletions Civi/Core/SettingsMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
*/
class SettingsMetadata {

const ALL = 'all';

/**
* WARNING: This interface may change.
*
Expand Down Expand Up @@ -72,25 +70,15 @@ public static function getMetadata($filters = [], $domainID = NULL) {

$cache = \Civi::cache('settings');
$cacheString = 'settingsMetadata_' . $domainID . '_';
// the caching into 'All' seems to be a duplicate of caching to
// settingsMetadata__ - I think the reason was to cache all settings as defined & then those altered by a hook
$settingsMetadata = $cache->get($cacheString);
$cached = is_array($settingsMetadata);

if (!$cached) {
$settingsMetadata = $cache->get(self::ALL);
if (empty($settingsMetadata)) {
global $civicrm_root;
$metaDataFolders = [$civicrm_root . '/settings'];
\CRM_Utils_Hook::alterSettingsFolders($metaDataFolders);
$settingsMetadata = self::loadSettingsMetaDataFolders($metaDataFolders);
$cache->set(self::ALL, $settingsMetadata);
}
}

\CRM_Utils_Hook::alterSettingsMetaData($settingsMetadata, $domainID, NULL);

if (!$cached) {
global $civicrm_root;
$metaDataFolders = [$civicrm_root . '/settings'];
\CRM_Utils_Hook::alterSettingsFolders($metaDataFolders);
$settingsMetadata = self::loadSettingsMetaDataFolders($metaDataFolders);
\CRM_Utils_Hook::alterSettingsMetaData($settingsMetadata, $domainID, NULL);
$cache->set($cacheString, $settingsMetadata);
}

Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/api/v3/SettingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public function testGetFields() {
public function testGetFieldsCaching() {
$settingsMetadata = array();
Civi::cache('settings')->set('settingsMetadata_' . \CRM_Core_Config::domainID() . '_', $settingsMetadata);
Civi::cache('settings')->set(\Civi\Core\SettingsMetadata::ALL, $settingsMetadata);
$result = $this->callAPISuccess('setting', 'getfields', array());
$this->assertArrayNotHasKey('customCSSURL', $result['values']);
$this->quickCleanup(array('civicrm_cache'));
Expand Down

0 comments on commit 9d9d98f

Please sign in to comment.