From 522e4c6c767b31efd3ba015db549fe65687b2b22 Mon Sep 17 00:00:00 2001 From: Brendan Heywood Date: Sun, 1 Nov 2020 13:55:41 +1100 Subject: [PATCH] MDL-47456 core: Remove redundant DB call during bootstrap --- lib/moodlelib.php | 45 ++++++++------------------------------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index ae47df302849f..7532952f55cdf 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1457,8 +1457,6 @@ function set_config($name, $value, $plugin=null) { * * NOTE: this function is called from lib/db/upgrade.php * - * @static string|false $siteidentifier The site identifier is not cached. We use this static cache so - * that we need only fetch it once per request. * @param string $plugin full component name * @param string $name default null * @return mixed hash-like object or single value, return false no config found @@ -1467,52 +1465,29 @@ function set_config($name, $value, $plugin=null) { function get_config($plugin, $name = null) { global $CFG, $DB; - static $siteidentifier = null; - if ($plugin === 'moodle' || $plugin === 'core' || empty($plugin)) { $forced =& $CFG->config_php_settings; - $iscore = true; + $table = 'config'; + $filter = []; $plugin = 'core'; } else { if (array_key_exists($plugin, $CFG->forced_plugin_settings)) { $forced =& $CFG->forced_plugin_settings[$plugin]; } else { - $forced = array(); + $forced = []; } - $iscore = false; + $table = 'config_plugins'; + $filter = ['plugin' => $plugin]; } - if ($siteidentifier === null) { - try { - // This may fail during installation. - // If you have a look at {@link initialise_cfg()} you will see that this is how we detect the need to - // install the database. - $siteidentifier = $DB->get_field('config', 'value', array('name' => 'siteidentifier')); - } catch (dml_exception $ex) { - // Set siteidentifier to false. We don't want to trip this continually. - $siteidentifier = false; - throw $ex; - } - } - - if (!empty($name)) { - if (array_key_exists($name, $forced)) { - return (string)$forced[$name]; - } else if ($name === 'siteidentifier' && $plugin == 'core') { - return $siteidentifier; - } + if (!empty($name) && array_key_exists($name, $forced)) { + return (string)$forced[$name]; } $cache = cache::make('core', 'config'); $result = $cache->get($plugin); if ($result === false) { - // The user is after a recordset. - if (!$iscore) { - $result = $DB->get_records_menu('config_plugins', array('plugin' => $plugin), '', 'name,value'); - } else { - // This part is not really used any more, but anyway... - $result = $DB->get_records_menu('config', array(), '', 'name,value');; - } + $result = $DB->get_records_menu($table, $filter, '', 'name,value'); $cache->set($plugin, $result); } @@ -1523,10 +1498,6 @@ function get_config($plugin, $name = null) { return false; } - if ($plugin === 'core') { - $result['siteidentifier'] = $siteidentifier; - } - foreach ($forced as $key => $value) { if (is_null($value) or is_array($value) or is_object($value)) { // We do not want any extra mess here, just real settings that could be saved in db.