From b7198b85f8b2cdd39129f05c1fde299472cabd94 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Sat, 22 Sep 2012 15:55:02 +0000 Subject: [PATCH] Stop cleaning the cache of a post's children. Ancestors are no longer cached against the post object, which means this kind of walking is unnecessary. It is also prohibitively expensive with large hierarchies. We need to remove post_ancestors non-persistent caching for this. get_post_ancestors() can simply rely on the caching of get_post() instead. Previously, it was a direct query, hence the extra layers of caching and clearing. Child cache clearing stays in wp_delete_post() as children get a new parent. fixes #11399. git-svn-id: https://develop.svn.wordpress.org/trunk@21952 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/load.php | 2 +- wp-includes/post.php | 17 ++--------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/wp-includes/load.php b/wp-includes/load.php index 7ad0341fb0..f998596525 100644 --- a/wp-includes/load.php +++ b/wp-includes/load.php @@ -410,7 +410,7 @@ function wp_start_object_cache() { if ( function_exists( 'wp_cache_add_global_groups' ) ) { wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); - wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins', 'post_ancestors' ) ); + wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); } } diff --git a/wp-includes/post.php b/wp-includes/post.php index cac125efc7..613c2f4f6c 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -557,7 +557,6 @@ function get_post_ancestors( $post ) { $post = get_post( $post ); - if ( ! $ancestors = wp_cache_get( $post->ID, 'post_ancestors' ) ) { $ancestors = array(); if ( !empty( $post->post_parent ) && $post->ID != $post->post_parent ) { @@ -572,9 +571,6 @@ function get_post_ancestors( $post ) { } } - wp_cache_add( $post->ID, $ancestors, 'post_ancestors' ); - } - return $ancestors; } @@ -2218,8 +2214,8 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { clean_post_cache( $post ); - if ( is_post_type_hierarchical( $post->post_type ) ) { - foreach ( (array) $children as $child ) + if ( is_post_type_hierarchical( $post->post_type ) && $children ) { + foreach ( $children as $child ) clean_post_cache( $child ); } @@ -4500,15 +4496,6 @@ function clean_post_cache( $post ) { wp_cache_delete( 'all_page_ids', 'posts' ); do_action( 'clean_page_cache', $post->ID ); } - - if ( $children = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_type FROM $wpdb->posts WHERE post_parent = %d", $post->ID) ) ) { - foreach ( $children as $child ) { - // Loop detection - if ( $child->ID == $post->ID ) - continue; - clean_post_cache( $child ); - } - } } /**