WordPress.org

Make WordPress Core

Ticket #11399: cpc.patch

File cpc.patch, 1.6 KB (added by jwriteclub, 10 years ago)

Changes clean_post_cache to (in theory) reduce database calls

  • post.php

     
    39243924 *
    39253925 * @uses do_action() Calls 'clean_post_cache' on $id before adding children (if any).
    39263926 *
    3927  * @param int $id The Post ID in the cache to clean
     3927 * @param int $id Optional The Post ID in the cache to clean
     3928 * @param array $found A list of nodes that have already been found
    39283929 */
    3929 function clean_post_cache($id) {
     3930function clean_post_cache($id,$found=null) {
    39303931        global $_wp_suspend_cache_invalidation, $wpdb;
    39313932
    39323933        if ( !empty($_wp_suspend_cache_invalidation) )
    39333934                return;
    39343935
     3936        if ( $found == null )
     3937           $found = array();
     3938
    39353939        $id = (int) $id;
    39363940
    3937         wp_cache_delete($id, 'posts');
    3938         wp_cache_delete($id, 'post_meta');
     3941        if ( array_key_exists($id,$found) )
     3942                return;
    39393943
    3940         clean_object_term_cache($id, 'post');
     3944        $found[$id] = true;
    39413945
    3942         wp_cache_delete( 'wp_get_archives', 'general' );
    3943 
    3944         do_action('clean_post_cache', $id);
    3945 
    39463946        if ( $children = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d", $id) ) ) {
    39473947                foreach( $children as $cid )
    39483948                        clean_post_cache( $cid );
    39493949        }
    39503950
    3951         if ( is_multisite() )
    3952                 wp_cache_delete( $wpdb->blogid . '-' . $id, 'global-posts' );
     3951        foreach ( $found as $id => $val )
     3952        {
     3953                wp_cache_delete($id, 'posts');
     3954                wp_cache_delete($id, 'post_meta');
     3955
     3956                clean_object_term_cache($id, 'post');
     3957
     3958                wp_cache_delete( 'wp_get_archives', 'general' );
     3959
     3960                do_action('clean_post_cache', $id);
     3961
     3962                if ( is_multisite() )
     3963                        wp_cache_delete( $wpdb->blogid . '-' . $id, 'global-posts' );
     3964        }
    39533965}
    39543966
    39553967/**