Add post ancestors to the cache for the post object. see #6702 for trunk

git-svn-id: http://svn.automattic.com/wordpress/trunk@7694 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-04-16 17:23:17 +00:00
parent d814986be2
commit a60abc0904
1 changed files with 15 additions and 17 deletions

View File

@ -165,20 +165,18 @@ function &get_post(&$post, $output = OBJECT, $filter = 'raw') {
else else
return $null; return $null;
} elseif ( is_object($post) ) { } elseif ( is_object($post) ) {
_get_post_ancestors($post);
wp_cache_add($post->ID, $post, 'posts'); wp_cache_add($post->ID, $post, 'posts');
$_post = &$post; $_post = &$post;
} else { } else {
$post = (int) $post; $post = (int) $post;
if ( ! $_post = wp_cache_get($post, 'posts') ) { if ( ! $_post = wp_cache_get($post, 'posts') ) {
$_post = & $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post)); $_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'); 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); $_post = sanitize_post($_post, $filter);
if ( $output == OBJECT ) { 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) ) ) if ( $children = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d", $id) ) )
foreach( $children as $cid ) foreach( $children as $cid )
clean_post_cache( $cid ); clean_page_cache( $cid );
} }
/** /**
@ -2965,7 +2963,7 @@ function _save_post_hook($post_id, $post) {
function _get_post_ancestors(&$_post) { function _get_post_ancestors(&$_post) {
global $wpdb; global $wpdb;
if ( !isset($_post->ancestors) ) if ( isset($_post->ancestors) )
return; return;
$_post->ancestors = array(); $_post->ancestors = array();