=== modified file 'includes/common.inc' --- includes/common.inc 2008-01-30 23:07:41 +0000 +++ includes/common.inc 2008-02-16 01:38:34 +0000 @@ -1460,6 +1460,7 @@ function l($text, $path, $options = arra * react to the closing of the page by calling hook_exit(). */ function drupal_page_footer() { + drupal_lookup_path('footer'); if (variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED) { page_set_cache(); } === modified file 'includes/path.inc' --- includes/path.inc 2007-11-04 16:42:45 +0000 +++ includes/path.inc 2008-02-17 00:48:34 +0000 @@ -59,34 +59,65 @@ function drupal_lookup_path($action, $pa $map = array(); $no_src = array(); } - elseif ($count > 0 && $path != '') { - if ($action == 'alias') { - if (isset($map[$path_language][$path])) { - return $map[$path_language][$path]; + elseif (($action == 'footer') || ($count > 0 && $path != '')) { + if (!isset($map[$path_language])) { + $cache = cache_get($_GET['q'] .':'. $path_language, 'cache_path'); + if ($cache) { + $map[$path_language] = $cache->data; + } + else { + $map[$path_language] = array(); + $result = db_query("SELECT path, alias FROM {path_alias_map} WHERE page_path = '%s' AND language = '%s'", $_GET['q'], $path_language); + while ($pair = db_fetch_array($result)) { + $map[$path_language][$pair['path']] = $pair['alias']; + } + cache_set($_GET['q'] .':'. $path_language, $map[$path_language], 'cache_path'); } - // Get the most fitting result falling back with alias without language - $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language)); - $map[$path_language][$path] = $alias; - return $alias; } - // Check $no_src for this $path in case we've already determined that there - // isn't a path that has this alias - elseif ($action == 'source' && !isset($no_src[$path_language][$path])) { - // Look for the value $path within the cached $map - $src = ''; - if (!isset($map[$path_language]) || !($src = array_search($path, $map[$path_language]))) { + switch ($action) { + case 'alias': + if (isset($map[$path_language][$path])) { + return $map[$path_language][$path]; + } // Get the most fitting result falling back with alias without language - if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language))) { - $map[$path_language][$src] = $path; + $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language)); + $map[$path_language][$path] = $alias; + return $alias; + case 'source': + // Check $no_src for this $path in case we've already determined that there + // isn't a path that has this alias + if (!isset($no_src[$path_language][$path])) { + // Look for the value $path within the cached $map + $src = ''; + if (!isset($map[$path_language]) || !($src = array_search($path, $map[$path_language]))) { + // Get the most fitting result falling back with alias without language + if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language))) { + $map[$path_language][$src] = $path; + } + 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 + // about any Drupal path. Thus cache to $no_src. + $no_src[$path_language][$path] = TRUE; + } + } + return $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 - // about any Drupal path. Thus cache to $no_src. - $no_src[$path_language][$path] = TRUE; + break; + case 'footer': + foreach ($map as $path_language => $entry) { + foreach ($entry as $path => $alias) { + // The new database layer will make this PostgreSQL and whatever + // compatible. Let's focus on functionality for now. + db_query("INSERT DELAYED INTO {path_alias_statistics_map} (page_path, language, path, alias) VALUES ('%s', '%s', '%s', '%s')", $_GET['q'], $path_language, $path, $alias); + } } - } - return $src; + foreach ($no_src as $language => $entry) { + foreach ($entry as $path => $v) { + db_query("INSERT DELAYED INTO {path_alias_statistics_src} (page_path, language, path) VALUES ('%s', '%s', '%s')", $_GET['q'], $path_language, $path); + } + } + break; } } === modified file 'modules/path/path.module' --- modules/path/path.module 2008-02-03 19:20:35 +0000 +++ modules/path/path.module 2008-02-16 22:58:01 +0000 @@ -215,3 +215,10 @@ function path_perm() { function path_load($pid) { return db_fetch_array(db_query('SELECT * FROM {url_alias} WHERE pid = %d', $pid)); } + +function path_cron() { + db_query_temporary('SELECT page_path, language, %f * MAX(c) AS cutoff FROM (SELECT page_path,language,path,alias,COUNT(*) AS c FROM path_alias_statistics_map GROUP BY page_path, language, path, alias) AS x GROUP BY page_path, language', variable_get('path_cutoff', .6), 'path_cutoff'); + db_query('DELETE FROM {path_alias_map}'); + db_query('INSERT INTO {path_alias_map} (page_path, language, path, alias, counter) SELECT page_path, language, path, alias, COUNT(*) FROM {path_alias_statistics_map} p GROUP BY page_path, language, path, alias HAVING COUNT(*) > (SELECT cutoff FROM page_cutoff pc WHERE pc.page_path = p.page_path AND pc.language = p.language)'); + db_query('DELETE FROM {path_alias_statistics_map}'); +}