Skip to:
Content

bbPress.org

Changeset 4041


Ignore:
Timestamp:
07/01/2012 11:50:30 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Caches:

  • Introduce bbp_clean_post_cache() to handle cleaning custom queries and post ancestors.
  • Audit use of _pre_ and _post_ forum/topic/reply actions and locations. Reposition and pass parents as needed.
  • Add 'bbp_clean_post_cache' action to necessary _pre_ and _post_ actions.
  • Fixes #1861.
Location:
branches/plugin/bbp-includes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-core-actions.php

    r4035 r4041  
    218218add_action( 'bbp_new_topic', 'bbp_global_access_auto_role' );
    219219add_action( 'bbp_new_reply', 'bbp_global_access_auto_role' );
     220
     221// Caches
     222add_action( 'bbp_new_forum_pre_extras',  'bbp_clean_post_cache' );
     223add_action( 'bbp_new_forum_post_extras', 'bbp_clean_post_cache' );
     224add_action( 'bbp_new_topic_pre_extras',  'bbp_clean_post_cache' );
     225add_action( 'bbp_new_topic_post_extras', 'bbp_clean_post_cache' );
     226add_action( 'bbp_new_reply_pre_extras',  'bbp_clean_post_cache' );
     227add_action( 'bbp_new_reply_post_extras', 'bbp_clean_post_cache' );
    220228
    221229/**
  • branches/plugin/bbp-includes/bbp-core-cache.php

    r4012 r4041  
    119119}
    120120new BBP_Skip_Children();
     121
     122/** General *******************************************************************/
     123
     124/**
     125 * Will clean a post in the cache.
     126 *
     127 * Will call to clean the term object cache associated with the post ID.
     128 *
     129 * @since bbPress (r4040)
     130 *
     131 * @uses do_action() Calls 'bbp_clean_post_cache' on $id
     132 * @param object|int $post The post object or ID to remove from the cache
     133 */
     134function bbp_clean_post_cache( $post ) {
     135    global $wpdb;
     136
     137    // Bail if no post
     138    $post = get_post( $post );
     139    if ( empty( $post ) )
     140        return;
     141
     142    wp_cache_delete( $post->ID, 'posts'     );
     143    wp_cache_delete( $post->ID, 'post_meta' );
     144
     145    clean_object_term_cache( $post->ID, $post->post_type );
     146
     147    do_action( 'bbp_clean_post_cache', $post->ID, $post );
     148
     149    // Child query types to clean
     150    $post_types = array( bbp_get_topic_post_type(), bbp_get_forum_post_type(), bbp_get_reply_post_type() );
     151
     152    // Loop through query types and clean caches
     153    foreach ( $post_types as $post_type ) {
     154        wp_cache_delete( 'bbp_get_forum_'     . $post->ID . '_reply_id',                              'bbpress' );
     155        wp_cache_delete( 'bbp_parent_'        . $post->ID . '_type_' . $post_type . '_child_last_id', 'bbpress' );
     156        wp_cache_delete( 'bbp_parent_'        . $post->ID . '_type_' . $post_type . '_child_count',   'bbpress' );
     157        wp_cache_delete( 'bbp_parent_public_' . $post->ID . '_type_' . $post_type . '_child_ids',     'bbpress' );
     158        wp_cache_delete( 'bbp_parent_all_'    . $post->ID . '_type_' . $post_type . '_child_ids',     'bbpress' );
     159    }
     160
     161    // Invalidate parent caches
     162    if ( $parent = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_type FROM $wpdb->posts WHERE ID = %d", $post->post_parent ) ) )
     163        bbp_clean_post_cache( $parent );
     164}
  • branches/plugin/bbp-includes/bbp-forum-functions.php

    r4026 r4041  
    229229    /** Additional Actions (Before Save) **************************************/
    230230
    231     do_action( 'bbp_new_forum_pre_extras' );
    232 
    233231    // Bail if errors
    234232    if ( bbp_has_errors() )
     
    236234
    237235    /** No Errors *************************************************************/
     236
     237    do_action( 'bbp_new_forum_pre_extras', $forum_parent_id );
    238238
    239239    // Add the content of the form to $forum_data as an array
  • branches/plugin/bbp-includes/bbp-reply-functions.php

    r4025 r4041  
    228228
    229229    /** Additional Actions (Before Save) **************************************/
    230 
    231     do_action( 'bbp_new_reply_pre_extras' );
    232230   
    233231    // Bail if errors
     
    236234
    237235    /** No Errors *************************************************************/
     236
     237    do_action( 'bbp_new_reply_pre_extras', $topic_id, $forum_id );
    238238
    239239    // Add the content of the form to $reply_data as an array
  • branches/plugin/bbp-includes/bbp-topic-functions.php

    r4025 r4041  
    265265    /** No Errors *************************************************************/
    266266
    267     do_action( 'bbp_new_topic_pre_extras' );
     267    do_action( 'bbp_new_topic_pre_extras', $forum_id );
    268268
    269269    // Add the content of the form to $topic_data as an array.
Note: See TracChangeset for help on using the changeset viewer.