Commit 8636519a authored by robertDouglass's avatar robertDouglass
Browse files

Cache path lookups. This reduces the number of db queries by a huge number if...

Cache path lookups. This reduces the number of db queries by a huge number if you have pages with path aliases.
parent ced01ec2
Index: includes/path.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/path.inc,v
retrieving revision 1.13
diff -u -r1.13 path.inc
--- includes/path.inc 23 Dec 2006 22:04:52 -0000 1.13
+++ includes/path.inc 13 Jan 2007 20:43:53 -0000
@@ -52,14 +52,31 @@
if ($action == 'wipe') {
$map = array();
$no_src = array();
+ dmemcache_flush('alias');
+ dmemcache_flush('src');
+ dmemcache_flush('path_count');
}
elseif ($count > 0 && $path != '') {
if ($action == 'alias') {
+ // static cache
if (isset($map[$path])) {
return $map[$path];
}
+ // memcache
+ if ($alias = dmemcache_get($path, 'alias')) {
+ $map[$path] = $alias['value'];
+ return $alias['value'];
+ }
+ // database
$alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path));
$map[$path] = $alias;
+ if (!$alias) {
+ $mc_value = array('value' => $alias, 'filler' => 'blah');
+ dmemcache_set($path, $mc_value, 300, 'alias');
+ }
+ else {
+ dmemcache_set($path, array('value' => $alias), 300, 'alias');
+ }
return $alias;
}
// Check $no_src for this $path in case we've already determined that there
@@ -67,9 +84,14 @@
elseif ($action == 'source' && !isset($no_src[$path])) {
// Look for the value $path within the cached $map
if (!$src = array_search($path, $map)) {
- if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) {
+ if ($mc_src = dmemcache_get($path, 'src')) {
+ $src = $mc_src['value'];
$map[$src] = $path;
}
+ else if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) {
+ $map[$src] = $path;
+ dmemcache_set($path, array('value' => $src), 300, 'src');
+ }
else {
// We can't record anything into $map because we do not have a valid
// index and there is no need because we have not learned anything
@@ -77,6 +99,7 @@
$no_src[$path] = TRUE;
}
}
+
return $src;
}
}
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