diff --git a/main/admin/settings.php b/main/admin/settings.php index f19a3ed35f..88c44c7e63 100755 --- a/main/admin/settings.php +++ b/main/admin/settings.php @@ -95,6 +95,8 @@ $form_search_html = $form_search->returnForm(); $url_id = api_get_current_access_url_id(); $settings = null; +$flushSettings = false; +$cacheAvailable = api_get_configuration_value('apc'); // Build the form. if (!empty($_GET['category']) && @@ -105,6 +107,7 @@ if (!empty($_GET['category']) && $settings = $settings_array['settings']; $settings_by_access_list = $settings_array['settings_by_access_list']; $form = generateSettingsForm($settings, $settings_by_access_list); + $multipleUrlsEnabled = false; if ($form->validate()) { $values = $form->exportValues(); @@ -113,6 +116,7 @@ if (!empty($_GET['category']) && $un_mark_all = false; if (api_is_multiple_url_enabled()) { + $multipleUrlsEnabled = true; if (isset($values['buttons_in_action_right']) && isset($values['buttons_in_action_right']['mark_all']) ) { @@ -147,6 +151,7 @@ if (!empty($_GET['category']) && ]; api_set_setting_simple($params); } + $flushSettings = true; } } } @@ -208,6 +213,7 @@ if (!empty($_GET['category']) && access_url = ".intval($url_id)." AND type IN ('checkbox', 'radio') "; $res = Database::query($sql); + $flushSettings = true; } // Save the settings. @@ -286,6 +292,7 @@ if (!empty($_GET['category']) && foreach ($value as $subkey => $subvalue) { $result = api_set_setting($key, 'true', $subkey, null, $url_id); } + $flushSettings = true; } } @@ -299,7 +306,25 @@ if (!empty($_GET['category']) && api_get_utc_datetime(), $user_id ); - + if ($cacheAvailable && $flushSettings) { + // Delete the APCu-stored settings array, if present + $apcRootVarName = api_get_configuration_value('apc_prefix').'settings_'; + $apcVarName = $apcRootVarName.$url_id; + apcu_delete($apcVarName); + if ($multipleUrlsEnabled && $url_id === 1) { + // if we are on the main URL of a multi-url portal, we must + // invalidate the cache for all other URLs as well as some + // main settings span multiple URLs + $urls = api_get_access_urls(); + foreach ($urls as $i => $row) { + if ($row['id'] == 1) { + continue; + } + $apcVarName = $apcRootVarName.$row['id']; + apcu_delete($apcVarName); + } + } + } // Add event configuration settings variable to the system log. if (is_array($keys) && count($keys) > 0) { foreach ($keys as $variable) { diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index 80019cce0d..bce433d876 100755 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -6390,6 +6390,25 @@ function api_get_access_url($id, $returnDefault = true) */ function api_get_settings($cat = null, $ordering = 'list', $access_url = 1, $url_changeable = 0) { + // Try getting settings from cache first (avoids query w/ ~375 rows result) + $apcVarName = ''; + $apcVar = []; + $cacheAvailable = api_get_configuration_value('apc'); + if ($cacheAvailable) { + $apcVarName = api_get_configuration_value('apc_prefix'). + 'settings_'. + $access_url + ; + $catName = (empty($cat) ? 'global' : $cat); + + if (apcu_exists($apcVarName)) { + $apcVar = apcu_fetch($apcVarName); + if (!empty($apcVar[$catName]) && !empty($apcVar[$catName][$ordering]) && isset($apcVar[$catName][$ordering][$url_changeable])) { + return $apcVar[$catName][$ordering][$url_changeable]; + } + } + } + // Could not find settings in cache (or already expired), so query DB $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); $access_url = (int) $access_url; $where_condition = ''; @@ -6417,6 +6436,18 @@ function api_get_settings($cat = null, $ordering = 'list', $access_url = 1, $url } $result = Database::store_result($result, 'ASSOC'); + if ($cacheAvailable) { + // If we got here, it means cache is available but the settings + // were not recently stored, so now we have them, let's store them + if (empty($apcVar[$catName])) { + $apcVar[$catName] = []; + } + if (empty($apcVar[$catName][$ordering])) { + $apcVar[$catName][$ordering] = []; + } + $apcVar[$catName][$ordering][$url_changeable] = $result; + apcu_store($apcVarName, $apcVar, 600); + } return $result; }