added cache_pages to avoid making 1+X queries everytime wp_list_pages is called, where X is the number of pages

git-svn-id: http://svn.automattic.com/wordpress/trunk@2354 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
michelvaldrighi 2005-02-16 15:12:04 +00:00
parent 8e770d3e6e
commit b361854d4f
2 changed files with 46 additions and 33 deletions

View File

@ -941,10 +941,14 @@ function remove_action($tag, $function_to_remove, $priority = 10) {
remove_filter($tag, $function_to_remove, $priority);
}
function get_page_uri($page) {
global $wpdb;
$page = $wpdb->get_row("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE ID = '$page'");
function get_page_uri($page_id) {
global $wpdb, $cache_pages;
if (!isset($cache_pages[$page_id])) {
$cache_pages[$page_id] = $wpdb->get_row("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE ID = '$page_id'");
}
$page = $cache_pages[$page_id];
$uri = urldecode($page->post_name);
// A page cannot be it's own parent.

View File

@ -260,7 +260,9 @@ function the_meta() {
//
function get_pages($args = '') {
global $wpdb;
global $wpdb, $cache_pages;
if (!isset($cache_pages) || empty($cache_pages)) {
parse_str($args, $r);
@ -287,7 +289,7 @@ function get_pages($args = '') {
}
$pages = $wpdb->get_results("SELECT " .
"ID, post_title,post_parent " .
"ID, post_title, post_name, post_parent " .
"$dates " .
"FROM $wpdb->posts " .
"WHERE post_status = 'static' " .
@ -295,7 +297,13 @@ function get_pages($args = '') {
"$exclusions " .
"ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);
return $pages;
foreach($pages as $page) {
$cache_pages[$page->ID] = $page;
}
}
return $cache_pages;
}
function wp_list_pages($args = '') {
@ -317,6 +325,7 @@ function wp_list_pages($args = '') {
foreach($pages as $page) {
// set the title for the current page
$page_tree[$page->ID]['title'] = $page->post_title;
$page_tree[$page->ID]['name'] = $page->post_name;
// set the selected date for the current page
// depending on the query arguments this is either