From 860c60d05bba88654fc95bbaccb941a4bd0f022d Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 16 Apr 2008 17:23:17 +0000 Subject: [PATCH] Add post ancestors to the cache for the post object. see #6702 for trunk git-svn-id: https://develop.svn.wordpress.org/trunk@7694 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/post.php | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 74ecfa5c4d..d006b59f94 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -165,20 +165,18 @@ function &get_post(&$post, $output = OBJECT, $filter = 'raw') { else return $null; } elseif ( is_object($post) ) { + _get_post_ancestors($post); wp_cache_add($post->ID, $post, 'posts'); $_post = &$post; } else { $post = (int) $post; if ( ! $_post = wp_cache_get($post, 'posts') ) { $_post = & $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post)); + _get_post_ancestors($_post); wp_cache_add($_post->ID, $_post, 'posts'); } } - // Populate the ancestors field. - // Not cached since we don't clear cache for ancestors when a post changes. - _get_post_ancestors($_post); - $_post = sanitize_post($_post, $filter); if ( $output == OBJECT ) { @@ -2739,7 +2737,7 @@ function clean_page_cache($id) { if ( $children = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d", $id) ) ) foreach( $children as $cid ) - clean_post_cache( $cid ); + clean_page_cache( $cid ); } /** @@ -2963,22 +2961,22 @@ function _save_post_hook($post_id, $post) { // function _get_post_ancestors(&$_post) { - global $wpdb; + global $wpdb; - if ( !isset($_post->ancestors) ) - return; + if ( isset($_post->ancestors) ) + return; - $_post->ancestors = array(); + $_post->ancestors = array(); - if ( empty($_post->post_parent) || $_post->ID == $_post->post_parent ) - return; + if ( empty($_post->post_parent) || $_post->ID == $_post->post_parent ) + return; - $id = $_post->ancestors[] = $_post->post_parent; - while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) { - if ( $id == $ancestor ) - break; - $id = $_post->ancestors[] = $ancestor; - } + $id = $_post->ancestors[] = $_post->post_parent; + while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) { + if ( $id == $ancestor ) + break; + $id = $_post->ancestors[] = $ancestor; + } } ?>