WordPress.org

Make WordPress Core

Changeset 7695


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.5/wp-includes/post.php

    r7646 r7695  
    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);
     
    27282726 */
    27292727function clean_page_cache($id) {
     2728    global $wpdb;
     2729    $id = (int) $id;
     2730
    27302731    clean_post_cache($id);
    27312732
     
    27342735
    27352736    do_action('clean_page_cache', $id);
     2737
     2738    if ( $children = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d", $id) ) )
     2739        foreach( $children as $cid )
     2740            clean_page_cache( $cid );
    27362741}
    27372742
     
    29572962
    29582963function _get_post_ancestors(&$_post) {
    2959     global $wpdb;
    2960 
    2961     if ( !empty($_post->ancestors) )
    2962         return;
    2963 
    2964     $_post->ancestors = array();
    2965 
    2966     if ( empty($_post->post_parent) || $_post->ID == $_post->post_parent )
    2967         return;
    2968 
    2969     $id = $_post->ancestors[] = $_post->post_parent;
    2970     while ( $ancestor = $wpdb->get_var("SELECT `post_parent` FROM $wpdb->posts WHERE ID= '{$id}' LIMIT 1") ) {
    2971         if ( $id == $ancestor )
    2972             break;
    2973         $id = $_post->ancestors[] = $ancestor;
    2974     }
     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    }
    29752980}
    29762981
Note: See TracChangeset for help on using the changeset viewer.