Commit d56ced2a authored by Dries's avatar Dries
Browse files

- Patch #10373 by jabart/killed: performance improvement: caching the variable table improves performance with 20% when serving cached pages.
parent 80086a9e
...@@ -38,14 +38,23 @@ function conf_init() { ...@@ -38,14 +38,23 @@ function conf_init() {
* file. * file.
*/ */
function variable_init($conf = array()) { function variable_init($conf = array()) {
$result = db_query('SELECT * FROM {variable} '); // NOTE: caching the variables improves performance with 20% when serving cached pages.
while ($variable = db_fetch_object($result)) { if ($cached = cache_get('variables')) {
if (!isset($conf[$variable->name])) { $variables = unserialize($cached->data);
$conf[$variable->name] = unserialize($variable->value); }
else {
$result = db_query('SELECT * FROM {variable}');
while ($variable = db_fetch_object($result)) {
$variables[$variable->name] = unserialize($variable->value);
} }
cache_set('variables', serialize($variables));
}
foreach ($conf as $name => $value) {
$variables[$name] = $value;
} }
return $conf; return $variables;
} }
/** /**
...@@ -78,6 +87,7 @@ function variable_set($name, $value) { ...@@ -78,6 +87,7 @@ function variable_set($name, $value) {
db_query("DELETE FROM {variable} WHERE name = '%s'", $name); 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) VALUES ('%s', '%s')", $name, serialize($value));
cache_clear_all('variables');
$conf[$name] = $value; $conf[$name] = $value;
} }
...@@ -92,6 +102,7 @@ function variable_del($name) { ...@@ -92,6 +102,7 @@ function variable_del($name) {
global $conf; global $conf;
db_query("DELETE FROM {variable} WHERE name = '%s'", $name); db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
cache_clear_all('variables');
unset($conf[$name]); unset($conf[$name]);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment