Skip to:
Content

bbPress.org


Ignore:
Timestamp:
08/09/2018 07:53:28 PM (7 years ago)
Author:
johnjamesjacoby
Message:

Tests: get all post type/status counts using bbp_get_child_counts().

  • Fix a broken test, and improve a few others
  • Update several count() instances that were doing expensive _ids() counts
  • Strategically bust the bbpress_posts query cache group on updates

This change improves general performance and count reliability by ensuring the accuracy of forum/topic/reply relationship totals.

File:
1 edited

Legend:

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

    r6814 r6848  
    7575    // Update the forum and hierarchy
    7676    bbp_update_forum( array(
    77         'forum_id' => $forum_id
     77        'forum_id'    => $forum_id,
     78        'post_parent' => $forum_data['post_parent']
    7879    ) );
    7980
     
    99100     */
    100101    do_action( 'bbp_insert_forum', (int) $forum_id );
     102
     103    // Bump the last changed cache
     104    wp_cache_set( 'last_changed', microtime(), 'bbpress_posts' );
    101105
    102106    // Return forum_id
     
    13671371
    13681372    // Get the topic's replies.
    1369     $replies = bbp_get_public_child_ids( $topic_id, bbp_get_reply_post_type() );
    1370     $count   = count( $replies );
     1373    $count = bbp_get_public_child_count( $topic_id, bbp_get_reply_post_type() );
    13711374
    13721375    // If we're unapproving, set count to negative.
     
    15931596    $forum_id = bbp_get_forum_id( $forum_id );
    15941597
     1598    // Maybe query for counts
    15951599    if ( empty( $subforums ) ) {
    1596         $subforums = count( bbp_forum_query_subforum_ids( $forum_id ) );
     1600        $subforums = bbp_get_public_child_count( $forum_id, bbp_get_forum_post_type() );
    15971601    }
    15981602
     
    16291633
    16301634    // Get total topics for this forum
    1631     $topics = (int) count( bbp_forum_query_topic_ids( $forum_id ) );
     1635    $topics = bbp_get_public_child_count( $forum_id, bbp_get_topic_post_type() );
    16321636
    16331637    // Calculate total topics in this forum
     
    17291733    $topic_ids   = bbp_forum_query_topic_ids( $forum_id );
    17301734    if ( ! empty( $topic_ids ) ) {
    1731         $query = new WP_Query( array(
    1732             'fields'          => 'ids',
    1733             'post_parent__in' => $topic_ids,
    1734             'post_status'     => bbp_get_public_status_id(),
    1735             'post_type'       => bbp_get_reply_post_type(),
    1736             'posts_per_page'  => -1,
    1737 
    1738             // Performance
    1739             'nopaging'               => true,
    1740             'suppress_filters'       => true,
    1741             'update_post_term_cache' => false,
    1742             'update_post_meta_cache' => false,
    1743             'ignore_sticky_posts'    => true,
    1744             'no_found_rows'          => true
    1745         ) );
    1746         $reply_count = ! empty( $query->posts ) ? count( $query->posts ) : 0;
    1747         unset( $query );
     1735        $reply_count = bbp_get_public_child_count( $forum_id, bbp_get_reply_post_type() );
    17481736    }
    17491737
     
    17881776    ), 'update_forum' );
    17891777
     1778    // Update the forum parent
     1779    bbp_update_forum_id( $r['forum_id'], $r['post_parent'] );
     1780
    17901781    // Last topic and reply ID's
    17911782    bbp_update_forum_last_topic_id( $r['forum_id'], $r['last_topic_id'] );
     
    18211812        ) );
    18221813    }
     1814
     1815    // Bump the custom query cache
     1816    wp_cache_set( 'last_changed', microtime(), 'bbpress_posts' );
    18231817}
    18241818
Note: See TracChangeset for help on using the changeset viewer.