From 3bacf431ae0d8159eb9a55e59f0061be26237e59 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 9 Mar 2005 03:16:30 +0000 Subject: [PATCH] Page caching fixes. Mosquito bugs 920, 927, and 934. git-svn-id: https://develop.svn.wordpress.org/trunk@2421 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/functions.php | 12 +++- wp-includes/template-functions-post.php | 76 ++++++++++++------------- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index fa99a34f63..38344d1c42 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -997,8 +997,11 @@ function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args function get_page_uri($page_id) { global $wpdb, $cache_pages; + $dates = ",UNIX_TIMESTAMP(post_modified) AS time_modified"; + $dates .= ",UNIX_TIMESTAMP(post_date) AS time_created"; + 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'"); + $cache_pages[$page_id] = $wpdb->get_row("SELECT ID, post_title, post_name, post_parent $dates FROM $wpdb->posts WHERE ID = '$page_id'"); } $page = $cache_pages[$page_id]; @@ -1010,7 +1013,12 @@ function get_page_uri($page_id) { } while ($page->post_parent != 0) { - $page = $wpdb->get_row("SELECT post_name, post_parent FROM $wpdb->posts WHERE ID = '$page->post_parent'"); + if (isset($cache_pages[$page->post_parent])) { + $page = $cache_pages[$page->post_parent]; + } else { + $page = $wpdb->get_row("SELECT ID, post_title, post_name, post_parent $dates FROM $wpdb->posts WHERE ID = '$page->post_parent'"); + $cache_pages[$page->ID] = $page; + } $uri = urldecode($page->post_name) . "/" . $uri; } diff --git a/wp-includes/template-functions-post.php b/wp-includes/template-functions-post.php index 7f5221d0ae..6245440856 100644 --- a/wp-includes/template-functions-post.php +++ b/wp-includes/template-functions-post.php @@ -264,50 +264,50 @@ function the_meta() { function get_pages($args = '') { global $wpdb, $cache_pages; - if (!isset($cache_pages) || empty($cache_pages)) { + parse_str($args, $r); - parse_str($args, $r); + if (!isset($r['child_of'])) $r['child_of'] = 0; + if (!isset($r['sort_column'])) $r['sort_column'] = 'post_title'; + if (!isset($r['sort_order'])) $r['sort_order'] = 'ASC'; - if (!isset($r['child_of'])) $r['child_of'] = 0; - if (!isset($r['sort_column'])) $r['sort_column'] = 'post_title'; - if (!isset($r['sort_order'])) $r['sort_order'] = 'ASC'; - - $exclusions = ''; - if (!empty($r['exclude'])) { - $expages = preg_split('/[\s,]+/',$r['exclude']); - if (count($expages)) { - foreach ($expages as $expage) { - $exclusions .= ' AND ID <> ' . intval($expage) . ' '; - } - } - } - - $dates = ",UNIX_TIMESTAMP(post_modified) AS time_modified"; - $dates .= ",UNIX_TIMESTAMP(post_date) AS time_created"; - - $post_parent = ''; - if ($r['child_of']) { - $post_parent = ' AND post_parent=' . $r['child_of'] . ' '; - } - - $pages = $wpdb->get_results("SELECT " . - "ID, post_title, post_name, post_parent " . - "$dates " . - "FROM $wpdb->posts " . - "WHERE post_status = 'static' " . - "$post_parent" . - "$exclusions " . - "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']); - - $cache_pages = array(); - if (count($pages)) { - foreach($pages as $page) { - $cache_pages[$page->ID] = $page; + $exclusions = ''; + if (!empty($r['exclude'])) { + $expages = preg_split('/[\s,]+/',$r['exclude']); + if (count($expages)) { + foreach ($expages as $expage) { + $exclusions .= ' AND ID <> ' . intval($expage) . ' '; } } } - return $cache_pages; + $dates = ",UNIX_TIMESTAMP(post_modified) AS time_modified"; + $dates .= ",UNIX_TIMESTAMP(post_date) AS time_created"; + + $post_parent = ''; + if ($r['child_of']) { + $post_parent = ' AND post_parent=' . $r['child_of'] . ' '; + } + + $pages = $wpdb->get_results("SELECT " . + "ID, post_title, post_name, post_parent " . + "$dates " . + "FROM $wpdb->posts " . + "WHERE post_status = 'static' " . + "$post_parent" . + "$exclusions " . + "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']); + + // Update page cache. + if (count($pages)) { + foreach($pages as $page) { + $cache_pages[$page->ID] = $page; + } + } + + if ( empty($pages) ) + $pages = array(); + + return $pages; } function wp_list_pages($args = '') {