Index: modules/system/system.install =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.install,v retrieving revision 1.57 diff -u -r1.57 system.install --- modules/system/system.install 8 Dec 2006 16:13:42 -0000 1.57 +++ modules/system/system.install 9 Dec 2006 15:41:58 -0000 @@ -530,6 +530,7 @@ db_query("CREATE TABLE {variable} ( name varchar(48) NOT NULL default '', value longtext NOT NULL, + prefetch tinyint NOT NULL default '0', PRIMARY KEY (name) ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.136 diff -u -r1.136 bootstrap.inc --- includes/bootstrap.inc 8 Dec 2006 12:09:54 -0000 1.136 +++ includes/bootstrap.inc 9 Dec 2006 20:43:36 -0000 @@ -294,6 +294,9 @@ * The variable table is composed of values that have been saved in the table * with variable_set() as well as those explicitly specified in the configuration * file. + * + * Only variables marked on variable_set as prefetchable are loaded here + * to avoid $conf cluttering */ function variable_init($conf = array()) { // NOTE: caching the variables improves performance by 20% when serving cached pages. @@ -301,7 +304,7 @@ $variables = unserialize($cached->data); } else { - $result = db_query('SELECT * FROM {variable}'); + $result = db_query('SELECT * FROM {variable} v WHERE v.prefetch = 1'); while ($variable = db_fetch_object($result)) { $variables[$variable->name] = unserialize($variable->value); } @@ -328,7 +331,16 @@ function variable_get($name, $default) { global $conf; - return isset($conf[$name]) ? $conf[$name] : $default; + if (isset($conf[$name])) { + $variable = $conf[$name]; + } + else { + /* cannot rely on db_result returning FALSE: this can be a valid result */ + $o = db_fetch_object(db_query("SELECT value FROM {variable} WHERE name='%s'", $name)); + $variable = isset($o) ? unserialize($o->value): $default; + $conf[$name] = $variable; + } + return $variable; } /** @@ -339,13 +351,18 @@ * @param $value * The value to set. This can be any PHP data type; these functions take care * of serialization as necessary. + * @param $prefetch + * Is this variable to be loaded during variable_init ? Defaults to 1 + * as this is the standard behaviour in earlier Drupal versions. If set to 0, + * variable will not be prefetched but will still be cached when retrieved + * using variable_get */ -function variable_set($name, $value) { +function variable_set($name, $value, $prefetch = 1) { global $conf; db_lock_table('variable'); db_query("DELETE FROM {variable} WHERE name = '%s'", $name); - db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value)); + db_query("INSERT INTO {variable} (name, value, prefetch) VALUES ('%s', '%s', %d)", $name, serialize($value), $prefetch); db_unlock_tables(); cache_clear_all('variables', 'cache');