Skip to:
Content

bbPress.org

Changeset 6585


Ignore:
Timestamp:
06/19/2017 05:05:18 AM (8 years ago)
Author:
johnjamesjacoby
Message:

Cache: make bbp_clean_post_cache() an action-only function.

Instead of calling bbp_clean_post_cache() directly, we'll call clean_post_cache() as per normal and hook bbp_clean_post_cache() to the end of it. This reduces a bunch of superfluous cache invalidation from occurring back-to-back.

We'll also only ever update the last_changed cache key when we've reached the forum-root. This makes sure that subsequent recursive calls up the post_parent tree are dealing with the same last_changed value until the end.

This change will reduce the number of cache invalidation calls by a large amount, improving functional performance for database writes to the post & postmeta tables.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/core/actions.php

    r6551 r6585  
    385385add_action( 'bbp_user_edit_after', 'bbp_user_edit_after' );
    386386
    387 // New forum/topic/reply caches
    388 // @todo Investigate why clearing is necessary on both pre & post hooks
    389 add_action( 'bbp_new_forum_pre_extras',  'bbp_clean_post_cache' );
    390 add_action( 'bbp_new_forum_post_extras', 'bbp_clean_post_cache' );
    391 add_action( 'bbp_new_topic_pre_extras',  'bbp_clean_post_cache' );
    392 add_action( 'bbp_new_topic_post_extras', 'bbp_clean_post_cache' );
    393 add_action( 'bbp_new_reply_pre_extras',  'bbp_clean_post_cache' );
    394 add_action( 'bbp_new_reply_post_extras', 'bbp_clean_post_cache' );
    395 
    396387// Clean bbPress post caches when WordPress's is cleaned
    397388add_action( 'clean_post_cache', 'bbp_clean_post_cache', 10, 2 );
  • trunk/src/includes/core/cache.php

    r6583 r6585  
    136136function bbp_clean_post_cache( $post_id = null, $post = null ) {
    137137
    138     // Get the post object.
    139     if ( null !== $post ) {
    140         $post = get_post( $post );
    141     } else {
    142         $post = get_post( $post_id );
    143     }
    144 
    145     // Bail if no post
    146     if ( empty( $post ) ) {
    147         return;
    148     }
    149 
    150138    // Child query types to clean
    151139    $post_types = array(
     
    159147        return;
    160148    }
    161 
    162     // Be sure we haven't recached the post data
    163     wp_cache_delete( $post->ID, 'posts'     );
    164     wp_cache_delete( $post->ID, 'post_meta' );
    165 
    166     // Clean the term cache for the given post
    167     clean_object_term_cache( $post->ID, $post->post_type );
    168 
    169     // Bump the last_changed cache
    170     wp_cache_set( 'last_changed', microtime(), 'bbpress_posts' );
    171149
    172150    /**
     
    182160    // Invalidate parent caches
    183161    if ( ! empty( $post->post_parent ) ) {
    184         bbp_clean_post_cache( $post->post_parent );
     162        clean_post_cache( $post->post_parent );
     163
     164    // Only bump `last_changed` when forum-root is reached
     165    } else {
     166        wp_cache_set( 'last_changed', microtime(), 'bbpress_posts' );
    185167    }
    186168}
  • trunk/src/includes/forums/functions.php

    r6583 r6585  
    833833        $bbp_db->update( $bbp_db->posts, array( 'post_status' => bbp_get_public_status_id() ), array( 'ID' => $forum_id ) );
    834834        wp_transition_post_status( bbp_get_public_status_id(), $current_visibility, get_post( $forum_id ) );
    835         bbp_clean_post_cache( $forum_id );
     835        clean_post_cache( $forum_id );
    836836    }
    837837
     
    882882        $bbp_db->update( $bbp_db->posts, array( 'post_status' => bbp_get_private_status_id() ), array( 'ID' => $forum_id ) );
    883883        wp_transition_post_status( bbp_get_private_status_id(), $current_visibility, get_post( $forum_id ) );
    884         bbp_clean_post_cache( $forum_id );
     884        clean_post_cache( $forum_id );
    885885    }
    886886
     
    931931        $bbp_db->update( $bbp_db->posts, array( 'post_status' => bbp_get_hidden_status_id() ), array( 'ID' => $forum_id ) );
    932932        wp_transition_post_status( bbp_get_hidden_status_id(), $current_visibility, get_post( $forum_id ) );
    933         bbp_clean_post_cache( $forum_id );
     933        clean_post_cache( $forum_id );
    934934    }
    935935
  • trunk/src/includes/topics/functions.php

    r6573 r6585  
    911911    // Clean old and new forum caches before proceeding, to ensure subsequent
    912912    // calls to forum objects are using updated data.
    913     bbp_clean_post_cache( $old_forum_id );
    914     bbp_clean_post_cache( $new_forum_id );
     913    clean_post_cache( $old_forum_id );
     914    clean_post_cache( $new_forum_id );
    915915
    916916    // Update topic forum's ID
  • trunk/tests/phpunit/testcases/admin/tools.php

    r6524 r6585  
    161161        bbp_admin_repair_topic_voice_count();
    162162
    163         bbp_clean_post_cache( $t );
     163        clean_post_cache( $t );
    164164
    165165        $count = bbp_get_topic_voice_count( $t );
     
    215215        bbp_admin_repair_topic_hidden_reply_count();
    216216
    217         bbp_clean_post_cache( $t );
     217        clean_post_cache( $t );
    218218
    219219        $count = bbp_get_topic_reply_count_hidden( $t, true );
     
    662662        bbp_admin_repair_forum_meta();
    663663
    664         bbp_clean_post_cache( $f );
    665         bbp_clean_post_cache( $t );
    666         bbp_clean_post_cache( $r );
     664        clean_post_cache( $f );
     665        clean_post_cache( $t );
     666        clean_post_cache( $r );
    667667
    668668        // Forums should NOT have a _bbp_forum_id meta key
  • trunk/tests/phpunit/testcases/core/cache.php

    r6584 r6585  
    4949
    5050        // Clean the cache.
    51         bbp_clean_post_cache( $r );
     51        clean_post_cache( $r );
    5252
    5353        // Setup
  • trunk/tests/phpunit/testcases/topics/functions/counts.php

    r6330 r6585  
    127127
    128128        // ToDo: Update this to use bbp_delete_reply().
    129         bbp_clean_post_cache( $t );
     129        clean_post_cache( $t );
    130130        wp_delete_post( $r2, true );
    131131
Note: See TracChangeset for help on using the changeset viewer.