Make WordPress Core

Ticket #23167: caching_incrementors_for_get_pages.patch

File caching_incrementors_for_get_pages.patch, 2.4 KB (added by nprasath002, 12 years ago)
  • wp-includes/post.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    29252925
    29262926        clean_post_cache( $post_ID );
    29272927
     2928        if ( function_exists( 'wp_cache_incr' ) ) {
     2929                wp_cache_incr( 'last_changed', 1, 'posts' );
     2930        } else {
     2931                $last_changed = wp_cache_get( 'last_changed', 'posts' );
     2932                wp_cache_set( 'last_changed', $last_changed + 1, 'posts' );
     2933        }
     2934
    29282935        $post = get_post($post_ID);
    29292936
    29302937        if ( !empty($page_template) && 'page' == $data['post_type'] ) {
     
    36493656        if ( array_diff( $post_status, get_post_stati() ) )
    36503657                return $pages;
    36513658
    3652         $cache = array();
     3659        // $args can be whatever, only use the args defined in defaults to compute the key
    36533660        $key = md5( serialize( compact(array_keys($defaults)) ) );
    3654         if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) {
    3655                 if ( is_array($cache) && isset( $cache[ $key ] ) && is_array( $cache[ $key ] ) ) {
    3656                         // Convert to WP_Post instances
    3657                         $pages = array_map( 'get_post', $cache[ $key ] );
    3658                         $pages = apply_filters( 'get_pages', $pages, $r );
    3659                         return $pages;
    3660                 }
    3661         }
     3661        $last_changed = wp_cache_get( 'last_changed', 'posts' );
     3662        if ( ! $last_changed )
     3663                $last_changed = wp_cache_set( 'last_changed', 1, 'posts' );
     3664
     3665        $cache_key = "get_pages:$key:$last_changed";
     3666        if ( $cache = wp_cache_get( $cache_key, 'posts' ) ) {
     3667                // Convert to WP_Post instances
     3668                $pages = array_map( 'get_post', $cache );
     3669                $pages = apply_filters('get_pages', $pages, $r);
     3670                return $pages;
     3671        }
    36623672
    36633673        if ( !is_array($cache) )
    36643674                $cache = array();
     
    38273837                }
    38283838        }
    38293839
    3830         $cache[ $key ] = $pages;
    3831         wp_cache_set( 'get_pages', $cache, 'posts' );
     3840        $page_structure = array();
     3841        foreach ( $pages as $page )
     3842                $page_structure[] = $page->ID;
    38323843
     3844        wp_cache_set( $cache_key, $page_structure, 'posts' );
     3845
    38333846        // Convert to WP_Post instances
    38343847        $pages = array_map( 'get_post', $pages );
    38353848
     
    46624675        if ( 'page' == $post->post_type ) {
    46634676                wp_cache_delete( 'all_page_ids', 'posts' );
    46644677                do_action( 'clean_page_cache', $post->ID );
     4678        }
     4679
     4680        if ( function_exists( 'wp_cache_incr' ) ) {
     4681                wp_cache_incr( 'last_changed', 1, 'posts' );
     4682        } else {
     4683                $last_changed = wp_cache_get( 'last_changed', 'posts' );
     4684                wp_cache_set( 'last_changed', $last_changed + 1, 'posts' );
    46654685        }
    46664686}
    46674687