Ticket #22176: 22176.3.diff
File 22176.3.diff, 4.7 KB (added by , 13 years ago) |
---|
-
wp-includes/post.php
2224 2224 2225 2225 if ( is_post_type_hierarchical( $post->post_type ) && $children ) { 2226 2226 foreach ( $children as $child ) 2227 clean_post_cache( $child );2227 clean_post_cache( $child, 'delete_parent' ); 2228 2228 } 2229 2229 2230 2230 wp_clear_scheduled_hook('publish_future_post', array( $postid ) ); … … 4480 4480 * @uses do_action() Calls 'clean_post_cache' on $id before adding children (if any). 4481 4481 * 4482 4482 * @param object|int $post The post object or ID to remove from the cache 4483 * @param string $context The context in which clean_post_cache() is called. Default is empty string. 4483 4484 */ 4484 function clean_post_cache( $post ) {4485 function clean_post_cache( $post, $context = '' ) { 4485 4486 global $_wp_suspend_cache_invalidation, $wpdb; 4486 4487 4487 4488 if ( ! empty( $_wp_suspend_cache_invalidation ) ) … … 4498 4499 4499 4500 wp_cache_delete( 'wp_get_archives', 'general' ); 4500 4501 4501 do_action( 'clean_post_cache', $post->ID, $post );4502 do_action( 'clean_post_cache', $post->ID, $post, $context ); 4502 4503 4503 4504 if ( is_post_type_hierarchical( $post->post_type ) ) 4504 4505 wp_cache_delete( 'get_pages', 'posts' ); … … 4507 4508 wp_cache_delete( 'all_page_ids', 'posts' ); 4508 4509 do_action( 'clean_page_cache', $post->ID ); 4509 4510 } 4511 4512 // Increment last_changed to invalidate query caches except for contexts 4513 // where clean_post_cache() has already been called for this page load 4514 // and contexts which do not affect query results. 4515 if ( ! ( 'delete_parent' == $context || 'update_comment_count' == $context ) ) { 4516 if ( function_exists( 'wp_cache_incr' ) ) { 4517 wp_cache_incr( 'last_changed', 1, 'posts' ); 4518 } else { 4519 $last_changed = wp_cache_get( 'last_changed', 'posts' ); 4520 wp_cache_set( 'last_changed', $last_changed + 1, 'posts' ); 4521 } 4522 } 4510 4523 } 4511 4524 4512 4525 /** -
wp-includes/comment.php
1618 1618 $new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id) ); 1619 1619 $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) ); 1620 1620 1621 clean_post_cache( $post );1621 clean_post_cache( $post, 'update_comment_count' ); 1622 1622 1623 1623 do_action('wp_update_comment_count', $post_id, $new, $old); 1624 1624 do_action('edit_post', $post_id, $post); -
wp-includes/query.php
1279 1279 */ 1280 1280 var $thumbnails_cached = false; 1281 1281 1282 /** 1283 * The cache key for the posts_request_ids query cache. 1284 * 1285 * @since 3.6.0 1286 * @access private 1287 * @var string 1288 */ 1289 private $cache_key; 1290 1282 1291 /** 1283 1292 * Resets query flags to false. 1284 1293 * … … 2661 2670 2662 2671 $this->request = apply_filters( 'posts_request_ids', $this->request, $this ); 2663 2672 2664 $ids = $wpdb->get_col( $this->request ); 2673 $last_changed = wp_cache_get( 'last_changed', 'posts' ); 2674 if ( ! $last_changed ) 2675 $last_changed = wp_cache_set( 'last_changed', 1, 'posts' ); 2676 $this->cache_key = md5( $this->request ) . $last_changed; 2665 2677 2678 if ( ! $ids = wp_cache_get( $this->cache_key, 'posts' ) ) { 2679 $ids = $wpdb->get_col( $this->request ); 2680 wp_cache_set( $this->cache_key, $ids, 'posts' ); 2681 } 2682 2666 2683 if ( $ids ) { 2667 2684 $this->posts = $ids; 2668 2685 $this->set_found_posts( $q, $limits ); … … 2802 2819 if ( $q['no_found_rows'] || ! $this->posts ) 2803 2820 return; 2804 2821 2805 if ( ! empty( $limits ) ) 2806 $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) ); 2807 else 2808 $this->found_posts = count( $this->posts ); 2822 if ( ! $this->cache_key || ! $this->found_posts = wp_cache_get( $this->cache_key . '_found', 'posts' ) ) { 2823 if ( ! empty( $limits ) ) 2824 $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) ); 2825 else 2826 $this->found_posts = count( $this->posts ); 2809 2827 2810 $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );2828 $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); 2811 2829 2830 wp_cache_set( $this->cache_key . '_found', $this->found_posts, 'posts' ); 2831 } else { 2832 $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); 2833 } 2834 2812 2835 if ( ! empty( $limits ) ) 2813 2836 $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); 2814 2837 }