Index: .htaccess =================================================================== RCS file: /cvs/drupal/drupal/.htaccess,v retrieving revision 1.111 diff -u -p -r1.111 .htaccess --- .htaccess 23 Nov 2010 02:59:05 -0000 1.111 +++ .htaccess 31 Dec 2010 14:01:28 -0000 @@ -2,6 +2,10 @@ # Apache/PHP/Drupal settings: # +php_value auto_prepend_file /home/catch/www/scripts/xhprof/header.php +php_value auto_append_file /home/catch/www/scripts/xhprof/footer.php + + # Protect files and directories from prying eyes. Order allow,deny Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.460 diff -u -p -r1.460 bootstrap.inc --- includes/bootstrap.inc 30 Dec 2010 04:36:53 -0000 1.460 +++ includes/bootstrap.inc 31 Dec 2010 14:01:29 -0000 @@ -732,25 +732,14 @@ function drupal_get_filename($type, $nam function variable_initialize($conf = array()) { // NOTE: caching the variables improves performance by 20% when serving // cached pages. - if ($cached = cache_get('variables', 'cache_bootstrap')) { - $variables = $cached->data; + $cache = &drupal_static('variable'); + if ($cached = cache_get('variable_cache', 'cache_bootstrap')) { + $cache = $cached->data; } else { - // 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); - } + $cache = array('variables' => array(), 'defaults' => array()); } + $variables = $cache['variables']; foreach ($conf as $name => $value) { $variables[$name] = $value; @@ -778,8 +767,52 @@ function variable_initialize($conf = arr * @see variable_set() */ function variable_get($name, $default = NULL) { + $boo = $name == 'menu_masks'; global $conf; + if (isset($conf[$name])) { + return $conf[$name]; + } + // Use the advanced drupal_static() pattern, since this is called very often. + static $drupal_static_fast; + if (!isset($drupal_static_fast)) { + $drupal_static_fast['cache'] = &drupal_static('variable'); + } + $cache = &$drupal_static_fast['cache']; + // $cache is populated in variable_initialize() for each request. If it's not + // available here we are in a lower bootstrap phase where the database and + // cache system may not be available yet. + if (isset($cache)) { + // First check the cached list of variables that should use defaults. + if (isset($cache['defaults'][$name])) { + return $default; + } + // If the variable is neither in $conf, nor in $cache['defaults'] then + // query the database. + else { + // To avoid race conditions when setting the cache, acquire a lock. + // However only add variables to the persistent cache on GET and HEAD + // requests. + if ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD') { + $lock_acquired = lock_acquire('variable_cache', 30); + } + $result = db_query('SELECT value FROM {variable} WHERE name = :name', array(':name' => $name))->fetchField(); + if ($result) { + $value = unserialize($result); + $conf[$name] = $cache['variables'][$name] = $value; + } + else { + $cache['defaults'][$name] = 1; + } + // If a lock was successfully acquired, set the cache. + if (!empty($lock_acquired)) { + // In case another process has populated the variables cache since + // variable_initialize() was called, fetch it again to get the updated + // version. + cache_set('variable_cache', $cache, 'cache_bootstrap'); + } + } + } return isset($conf[$name]) ? $conf[$name] : $default; } @@ -802,9 +835,10 @@ function variable_get($name, $default = function variable_set($name, $value) { global $conf; + lock_acquire('variable_cache'); db_merge('variable')->key(array('name' => $name))->fields(array('value' => serialize($value)))->execute(); - - cache_clear_all('variables', 'cache_bootstrap'); + cache_clear_all('variable_cache', 'cache_bootstrap'); + lock_release('variable_cache'); $conf[$name] = $value; } @@ -825,10 +859,12 @@ function variable_set($name, $value) { function variable_del($name) { global $conf; + lock_acquire('variable_cache'); db_delete('variable') ->condition('name', $name) ->execute(); - cache_clear_all('variables', 'cache_bootstrap'); + cache_clear_all('variable_cache', 'cache_bootstrap'); + lock_release('variable_cache'); unset($conf[$name]); } Index: includes/install.core.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/install.core.inc,v retrieving revision 1.48 diff -u -p -r1.48 install.core.inc --- includes/install.core.inc 28 Dec 2010 18:17:27 -0000 1.48 +++ includes/install.core.inc 31 Dec 2010 14:01:32 -0000 @@ -241,6 +241,10 @@ function install_begin_request(&$install // This must go after drupal_bootstrap(), which unsets globals! global $conf; + // Initialize the locking system. + require_once DRUPAL_ROOT . '/' . variable_get('lock_inc', 'includes/lock.inc'); + lock_initialize(); + require_once DRUPAL_ROOT . '/modules/system/system.install'; require_once DRUPAL_ROOT . '/includes/common.inc'; require_once DRUPAL_ROOT . '/includes/file.inc';