Make WordPress Core


Ignore:
Timestamp:
04/16/2008 05:23:17 PM (19 years ago)
Author:
ryan
Message:

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

File:
1 edited

Legend:

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

    r7647 r7694  
    166166                        return $null;
    167167        } elseif ( is_object($post) ) {
     168                _get_post_ancestors($post);
    168169                wp_cache_add($post->ID, $post, 'posts');
    169170                $_post = &$post;
    … …  
    172173                if ( ! $_post = wp_cache_get($post, 'posts') ) {
    173174                        $_post = & $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post));
     175                        _get_post_ancestors($_post);
    174176                        wp_cache_add($_post->ID, $_post, 'posts');
    175177                }
    176178        }
    177 
    178         // Populate the ancestors field.
    179         // Not cached since we don't clear cache for ancestors when a post changes.
    180         _get_post_ancestors($_post);
    181179
    182180        $_post = sanitize_post($_post, $filter);
    … …  
    27402738        if ( $children = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d", $id) ) )
    27412739                foreach( $children as $cid )
    2742                         clean_post_cache( $cid );
     2740                        clean_page_cache( $cid );
    27432741}
    27442742
    … …  
    29642962
    29652963function _get_post_ancestors(&$_post) {
    2966     global $wpdb;
    2967 
    2968     if ( !isset($_post->ancestors) )
    2969         return;
    2970 
    2971     $_post->ancestors = array();
    2972 
    2973     if ( empty($_post->post_parent) || $_post->ID == $_post->post_parent )
    2974         return;
    2975 
    2976     $id = $_post->ancestors[] = $_post->post_parent;
    2977     while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) {
    2978         if ( $id == $ancestor )
    2979                 break;
    2980         $id = $_post->ancestors[] = $ancestor;
    2981     }
     2964        global $wpdb;
     2965
     2966        if ( isset($_post->ancestors) )
     2967                return;
     2968
     2969        $_post->ancestors = array();
     2970
     2971        if ( empty($_post->post_parent) || $_post->ID == $_post->post_parent )
     2972                return;
     2973
     2974        $id = $_post->ancestors[] = $_post->post_parent;
     2975        while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) {
     2976                if ( $id == $ancestor )
     2977                        break;
     2978                $id = $_post->ancestors[] = $ancestor;
     2979        }
    29822980}
    29832981
Note: See TracChangeset for help on using the changeset viewer.