Make WordPress Core

Ticket #10381: post.php.diff

File post.php.diff, 1.0 KB (added by shidouhikari, 15 years ago)

Another attempt to deal with post ancestors and cached posts

  • wp-includes/post.php

     
    366366        } elseif ( is_object($post) && empty($post->filter) ) {
    367367                _get_post_ancestors($post);
    368368                $_post = sanitize_post($post, 'raw');
     369                if ( $cached_post = wp_cache_get($_post->ID, 'posts') ) {
     370                        if ( ! isset($cached_post->ancestors) )
     371                                wp_cache_delete($_post->ID, 'posts');
     372                }
    369373                wp_cache_add($post->ID, $_post, 'posts');
    370374        } else {
    371375                if ( is_object($post) )
     
    374378                        $post_id = $post;
    375379
    376380                $post_id = (int) $post_id;
    377                 if ( ! $_post = wp_cache_get($post_id, 'posts') ) {
     381               
     382                if ( $_post = wp_cache_get($post_id, 'posts') ) {
     383                        if ( ! isset($_post->ancestors) ) {
     384                                _get_post_ancestors($_post);
     385                                wp_cache_set($_post->ID, $_post, 'posts');
     386                        }
     387                } elseif {
    378388                        $_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id));
    379389                        if ( ! $_post )
    380390                                return $null;