diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/bootstrap.inc | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index e0913cd49..3075a8ca2 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -743,13 +743,26 @@ function drupal_get_filename($type, $name, $filename = NULL) { * file. */ function variable_initialize($conf = array()) { - // NOTE: caching the variables improves performance by 20% when serving cached pages. + // NOTE: caching the variables improves performance by 20% when serving + // cached pages. if ($cached = cache_get('variables', 'cache_bootstrap')) { $variables = $cached->data; } else { - $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed()); - cache_set('variables', $variables, 'cache_bootstrap'); + // Cache miss. Avoid a stampede. + $name = 'variable_init'; + if (!lock_acquire($name, 1)) { + // Another request is building the variable cache. + // Wait, then re-run this function. + lock_wait($name); + return variable_initialize($conf); + } + else { + // Proceed with variable rebuild. + $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed()); + cache_set('variables', $variables, 'cache_bootstrap'); + lock_release($name); + } } foreach ($conf as $name => $value) { @@ -2169,6 +2182,10 @@ function _drupal_bootstrap_database() { function _drupal_bootstrap_variables() { global $conf; + // Initialize the lock system. + require_once DRUPAL_ROOT . '/' . variable_get('lock_inc', 'includes/lock.inc'); + lock_initialize(); + // Load variables from the database, but do not overwrite variables set in settings.php. $conf = variable_initialize(isset($conf) ? $conf : array()); // Load bootstrap modules. @@ -2182,10 +2199,6 @@ function _drupal_bootstrap_variables() { function _drupal_bootstrap_page_header() { bootstrap_invoke_all('boot'); - // Prepare for non-cached page workflow. - require_once DRUPAL_ROOT . '/' . variable_get('lock_inc', 'includes/lock.inc'); - lock_initialize(); - if (!drupal_is_cli()) { ob_start(); drupal_page_header(); |