Skip to content

Commit

Permalink
MDL-47456 core: Remove redundant DB call during bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanheywood committed Nov 16, 2020
1 parent 6ef4e66 commit 522e4c6
Showing 1 changed file with 8 additions and 37 deletions.
45 changes: 8 additions & 37 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand All @@ -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.
Expand Down

0 comments on commit 522e4c6

Please sign in to comment.