WordPress.org

Make WordPress Core

Changeset 21952


Ignore:
Timestamp:
09/22/2012 03:55:02 PM (8 years ago)
Author:
nacin
Message:

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.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/load.php

    r21715 r21952  
    411411    if ( function_exists( 'wp_cache_add_global_groups' ) ) {
    412412        wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
    413         wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins', 'post_ancestors' ) );
     413        wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
    414414    }
    415415}
  • trunk/wp-includes/post.php

    r21948 r21952  
    558558    $post = get_post( $post );
    559559
    560     if ( ! $ancestors = wp_cache_get( $post->ID, 'post_ancestors' ) ) {
    561560        $ancestors = array();
    562561
     
    572571            }
    573572        }
    574 
    575         wp_cache_add( $post->ID, $ancestors, 'post_ancestors' );
    576     }
    577573
    578574    return $ancestors;
     
    22192215    clean_post_cache( $post );
    22202216
    2221     if ( is_post_type_hierarchical( $post->post_type ) ) {
    2222         foreach ( (array) $children as $child )
     2217    if ( is_post_type_hierarchical( $post->post_type ) && $children ) {
     2218        foreach ( $children as $child )
    22232219            clean_post_cache( $child );
    22242220    }
     
    45014497        do_action( 'clean_page_cache', $post->ID );
    45024498    }
    4503 
    4504     if ( $children = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_type FROM $wpdb->posts WHERE post_parent = %d", $post->ID) ) ) {
    4505         foreach ( $children as $child ) {
    4506             // Loop detection
    4507             if ( $child->ID == $post->ID )
    4508                 continue;
    4509             clean_post_cache( $child );
    4510         }
    4511     }
    45124499}
    45134500
Note: See TracChangeset for help on using the changeset viewer.