Skip to:
Content

bbPress.org

Ticket #3203: speed-up-topic-trashing.diff

File speed-up-topic-trashing.diff, 2.7 KB (added by codex-m, 3 years ago)

Implement object caching on slow lines when deleting a topic

  • includes/forums/functions.php

     
    15231523                        'numberposts' => 1
    15241524                );
    15251525
    1526                 // Get the most recent topic in this forum_id
    1527                 $recent_topic = get_posts( $post_vars );
     1526                // Get the most recent topic in this forum_id   
     1527                $recent_topic = wp_cache_get( 'bbp_recent_topic_forum_' . $forum_id );
     1528                if ( false === $recent_topic ) {
     1529                    $recent_topic = get_posts( $post_vars );
     1530                    wp_cache_set( 'bbp_recent_topic_forum_' . $forum_id, $recent_topic );
     1531                }               
     1532               
    15281533                if ( ! empty( $recent_topic ) ) {
    15291534                        $topic_id = $recent_topic[0]->ID;
    15301535                }
     
    15881593                if ( ! empty( $topic_ids ) ) {
    15891594
    15901595                        // ...get the most recent reply from those topics...
    1591                         $reply_id = bbp_forum_query_last_reply_id( $forum_id, $topic_ids );
    1592 
     1596                    $topic_id_hash = md5( json_encode( $topic_ids ) );
     1597                    $reply_id = wp_cache_get( 'bbp_forum_query_last_reply_id_' . $forum_id . $topic_id_hash );
     1598                    if ( false === $reply_id ) {
     1599                        $reply_id = bbp_forum_query_last_reply_id( $forum_id, $topic_ids );
     1600                        wp_cache_set( 'bbp_forum_query_last_reply_id_' . $forum_id . $topic_id_hash, $reply_id );
     1601                    }
     1602                   
    15931603                        // ...and compare it to the most recent topic id...
    15941604                        $reply_id = ( $reply_id > max( $topic_ids ) ) ? $reply_id : max( $topic_ids );
    15951605                }
     
    16531663                // Don't count replies if the forum is a category
    16541664                $topic_ids = bbp_forum_query_topic_ids( $forum_id );
    16551665                if ( ! empty( $topic_ids ) ) {
    1656                         $active_id = bbp_forum_query_last_reply_id( $forum_id, $topic_ids );
     1666                    $topic_id_hash = md5( json_encode( $topic_ids ) );
     1667                    $active_id = wp_cache_get( 'bbp_forum_query_last_reply_id_' . $forum_id . $topic_id_hash );
     1668                    if ( false === $active_id ) {
     1669                        $active_id = bbp_forum_query_last_reply_id( $forum_id, $topic_ids );
     1670                        wp_cache_set( 'bbp_forum_query_last_reply_id_' . $forum_id . $topic_id_hash, $active_id );
     1671                    }                   
    16571672                        $active_id = $active_id > max( $topic_ids ) ? $active_id : max( $topic_ids );
    16581673
    16591674                // Forum has no topics
     
    22682283 *                        and forum id
    22692284 */
    22702285function bbp_forum_query_topic_ids( $forum_id ) {
    2271         $topic_ids = bbp_get_public_child_ids( $forum_id, bbp_get_topic_post_type() );
    2272 
     2286        $topic_ids = wp_cache_get( 'bbp_get_public_child_ids_forum_' . $forum_id );
     2287        if ( false === $topic_ids ) {
     2288            $topic_ids = bbp_get_public_child_ids( $forum_id, bbp_get_topic_post_type() );
     2289            wp_cache_set( 'bbp_get_public_child_ids_forum_' . $forum_id, $topic_ids );
     2290        }       
    22732291        return (array) apply_filters( 'bbp_forum_query_topic_ids', $topic_ids, $forum_id );
    22742292}
    22752293