diff -r c7c0fbc09788 -r 5e8dcbe22c24 web/wp-content/plugins/bbpress/includes/core/cache.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/wp-content/plugins/bbpress/includes/core/cache.php Tue Dec 04 18:43:10 2012 -0800 @@ -0,0 +1,168 @@ +updating_post = $post_id; + + // Skip related post cache invalidation. This prevents invalidating the + // caches of the child posts when there is no reason to do so. + add_action( 'clean_post_cache', array( $this, 'skip_related_posts' ) ); + } + + /** + * Skip cache invalidation of related posts if the post ID being invalidated + * is not the one that was just updated. + * + * @since bbPress (r4011) + * + * @param int $post_id The post ID of the cache being invalidated + * @return If invalid post data + */ + public function skip_related_posts( $post_id = 0 ) { + + // Bail if this post is not the current bbPress post + if ( empty( $post_id ) || ( $this->updating_post !== $post_id ) ) + return; + + // Stash the current cache invalidation value in a variable, so we can + // restore back to it nicely in the future. + global $_wp_suspend_cache_invalidation; + + $this->original_cache_invalidation = $_wp_suspend_cache_invalidation; + + // Turn off cache invalidation + wp_suspend_cache_invalidation( true ); + + // Restore cache invalidation + add_action( 'wp_insert_post', array( $this, 'restore_cache_invalidation' ) ); + } + + /** + * Restore the cache invalidation to its previous value. + * + * @since bbPress (r4011) + * @uses wp_suspend_cache_invalidation() + */ + public function restore_cache_invalidation() { + wp_suspend_cache_invalidation( $this->original_cache_invalidation ); + } +} +new BBP_Skip_Children(); + +/** General *******************************************************************/ + +/** + * Will clean a post in the cache. + * + * Will call to clean the term object cache associated with the post ID. + * + * @since bbPress (r4040) + * + * @uses do_action() Calls 'bbp_clean_post_cache' on $id + * @param object|int $_post The post object or ID to remove from the cache + */ +function bbp_clean_post_cache( $_post = '' ) { + + // Bail if no post + $_post = get_post( $_post ); + if ( empty( $_post ) ) + return; + + wp_cache_delete( $_post->ID, 'posts' ); + wp_cache_delete( $_post->ID, 'post_meta' ); + + clean_object_term_cache( $_post->ID, $_post->post_type ); + + do_action( 'bbp_clean_post_cache', $_post->ID, $_post ); + + // Child query types to clean + $post_types = array( + bbp_get_topic_post_type(), + bbp_get_forum_post_type(), + bbp_get_reply_post_type() + ); + + // Loop through query types and clean caches + foreach ( $post_types as $post_type ) { + wp_cache_delete( 'bbp_get_forum_' . $_post->ID . '_reply_id', 'bbpress' ); + wp_cache_delete( 'bbp_parent_' . $_post->ID . '_type_' . $post_type . '_child_last_id', 'bbpress' ); + wp_cache_delete( 'bbp_parent_' . $_post->ID . '_type_' . $post_type . '_child_count', 'bbpress' ); + wp_cache_delete( 'bbp_parent_public_' . $_post->ID . '_type_' . $post_type . '_child_ids', 'bbpress' ); + wp_cache_delete( 'bbp_parent_all_' . $_post->ID . '_type_' . $post_type . '_child_ids', 'bbpress' ); + } + + // Invalidate parent caches + if ( ! empty( $_post->post_parent ) ) { + bbp_clean_post_cache( $_post->post_parent ); + } +}