- Patch #561990 by catch, mikeytown2, nnewton: avoid variable_set() and variable_del() stampedes.
parent
41abf46f07
commit
42a86ff32d
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue