summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-06-24 18:56:10 +0000
committerDries Buytaert <dries@buytaert.net>2010-06-24 18:56:10 +0000
commit42a86ff32d1925aa279b43685223cde27dabfb11 (patch)
tree996d93f9b53c395f858df51d2606d1fa72d605cb
parent41abf46f07be1af6661f0aa4bed4cba2f36da429 (diff)
downloadbrdo-42a86ff32d1925aa279b43685223cde27dabfb11.tar.gz
brdo-42a86ff32d1925aa279b43685223cde27dabfb11.tar.bz2
- Patch #561990 by catch, mikeytown2, nnewton: avoid variable_set() and variable_del() stampedes.
-rw-r--r--includes/bootstrap.inc27
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();