Skip to:
Content

bbPress.org

Changeset 6717


Ignore:
Timestamp:
09/27/2017 07:23:53 AM (2 years ago)
Author:
johnjamesjacoby
Message:

Replies: performance optimization to bbp_update_reply_position().

This change uses wpdb::update() instead of wp_update_post() and juggles the bbp_clean_post_cache() filter, retaining object caches of related posts and queries, and also removes other unintended edit_post action interference.

Fixes #3169.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/replies/functions.php

    r6714 r6717  
    22162216    }
    22172217
     2218    // Get the current reply position
     2219    $current_position = get_post_field( 'menu_order', $reply_id );
     2220
     2221    // Bail if no change
     2222    if ( $reply_position === $current_position ) {
     2223        return false;
     2224    }
     2225
     2226    // Filters not removed
     2227    $removed = false;
     2228
    22182229    // Toggle revisions off as we are not altering content
    2219     if ( post_type_supports( bbp_get_reply_post_type(), 'revisions' ) ) {
    2220         $revisions_removed = true;
    2221         remove_post_type_support( bbp_get_reply_post_type(), 'revisions' );
     2230    if ( has_filter( 'clean_post_cache', 'bbp_clean_post_cache' ) ) {
     2231        $removed = true;
     2232        remove_filter( 'clean_post_cache', 'bbp_clean_post_cache', 10, 2 );
    22222233    }
    22232234
    22242235    // Update the replies' 'menu_order' with the reply position
    2225     wp_update_post( array(
    2226         'ID'         => $reply_id,
    2227         'menu_order' => $reply_position
    2228     ) );
     2236    $bbp_db = bbp_db();
     2237    $bbp_db->update( $bbp_db->posts, array( 'menu_order' => $reply_position ), array( 'ID' => $reply_id ) );
     2238    clean_post_cache( $reply_id );
    22292239
    22302240    // Toggle revisions back on
    2231     if ( true === $revisions_removed ) {
    2232         $revisions_removed = false;
    2233         add_post_type_support( bbp_get_reply_post_type(), 'revisions' );
     2241    if ( true === $removed ) {
     2242        $removed = false;
     2243        add_filter( 'clean_post_cache', 'bbp_clean_post_cache', 10, 2 );
    22342244    }
    22352245
     
    22492259
    22502260    // Get required data
     2261    $reply_position = 0;
    22512262    $reply_id       = bbp_get_reply_id( $reply_id );
    2252     $topic_id       = ! empty( $topic_id ) ? bbp_get_topic_id( $topic_id ) : bbp_get_reply_topic_id( $reply_id );
    2253     $reply_position = 0;
     2263    $topic_id       = ! empty( $topic_id )
     2264        ? bbp_get_topic_id( $topic_id )
     2265        : bbp_get_reply_topic_id( $reply_id );
    22542266
    22552267    // If reply is actually the first post in a topic, return 0
Note: See TracChangeset for help on using the changeset viewer.