Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/02/2017 04:39:49 PM (7 years ago)
Author:
johnjamesjacoby
Message:

Queries: nopaging audit.

  • In r6506 the nopaging query argument was added to various queries to avoid paginating results when it wasn't necessary. This resulted in a few queries (widgets mainly) not obeying their specific settings.
  • In #3123, other inconsistencies in our query arguments were uncovered, triggering the need to audit our query usages and equalize them once again.

This change brings all queries back to par with one another, specifically in regards to posts_per_page => -1 style queries, and queries where filters can be suppressed and meta/term caches should not be primed.

It also groups together the get_user_object_ids functions. These are now unused in bbPress proper, though were previously useful before the engagements API was in place. These queries are considered too inefficient to rely upon in large-scale applications, but are included to provide filterable wrappers should someone need them, or should we need to bring them back later.

Props thebrandonallen. Fixes #3123.

File:
1 edited

Legend:

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

    r6585 r6607  
    963963    // Query for private forums
    964964    $private_forums = new WP_Query( array(
    965         'fields'           => 'ids',
    966         'suppress_filters' => true,
    967         'post_type'        => bbp_get_forum_post_type(),
    968         'post_status'      => bbp_get_private_status_id(),
    969         'posts_per_page'   => -1,
     965        'fields'         => 'ids',
     966        'post_type'      => bbp_get_forum_post_type(),
     967        'post_status'    => bbp_get_private_status_id(),
     968        'posts_per_page' => -1,
    970969
    971970        // Performance
     971        'nopaging'               => true,
     972        'suppress_filters'       => true,
     973        'update_post_term_cache' => false,
     974        'update_post_meta_cache' => false,
    972975        'ignore_sticky_posts'    => true,
    973         'no_found_rows'          => true,
    974         'nopaging'               => true,
    975         'update_post_term_cache' => false,
    976         'update_post_meta_cache' => false
     976        'no_found_rows'          => true
    977977    ) );
    978978
     
    986986
    987987        // Performance
     988        'nopaging'               => true,
     989        'suppress_filters'       => true,
     990        'update_post_term_cache' => false,
     991        'update_post_meta_cache' => false,
    988992        'ignore_sticky_posts'    => true,
    989         'no_found_rows'          => true,
    990         'nopaging'               => true,
    991         'update_post_term_cache' => false,
    992         'update_post_meta_cache' => false
     993        'no_found_rows'          => true
    993994    ) );
    994995
     
    16031604 *                       i.e. the forum is automatically retrieved.
    16041605 * @param bool $total_count Optional. To return the total count or normal count?
    1605  
    16061606 * @return int Forum topic count
    16071607 */
     
    16621662        if ( empty( $topic_count ) ) {
    16631663            $query = new WP_Query( array(
    1664                 'fields'           => 'ids',
    1665                 'suppress_filters' => true,
    1666                 'post_parent'      => $forum_id,
    1667                 'post_status'      => array( bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id() ),
    1668                 'post_type'        => bbp_get_topic_post_type(),
    1669                 'posts_per_page'   => -1,
     1664                'fields'         => 'ids',
     1665                'post_parent'    => $forum_id,
     1666                'post_status'    => array( bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id() ),
     1667                'post_type'      => bbp_get_topic_post_type(),
     1668                'posts_per_page' => -1,
    16701669
    16711670                // Performance
     1671                'nopaging'               => true,
     1672                'suppress_filters'       => true,
    16721673                'update_post_term_cache' => false,
    16731674                'update_post_meta_cache' => false,
    16741675                'ignore_sticky_posts'    => true,
    1675                 'no_found_rows'          => true,
    1676                 'nopaging'               => true
     1676                'no_found_rows'          => true
    16771677            ) );
    16781678            $topic_count = $query->post_count;
     
    17201720    if ( ! empty( $topic_ids ) ) {
    17211721        $query = new WP_Query( array(
    1722             'fields'           => 'ids',
    1723             'suppress_filters' => true,
    1724             'post_parent__in'  => $topic_ids,
    1725             'post_status'      => bbp_get_public_status_id(),
    1726             'post_type'        => bbp_get_reply_post_type(),
    1727             'posts_per_page'   => -1,
     1722            'fields'          => 'ids',
     1723            'post_parent__in' => $topic_ids,
     1724            'post_status'     => bbp_get_public_status_id(),
     1725            'post_type'       => bbp_get_reply_post_type(),
     1726            'posts_per_page'  => -1,
    17281727
    17291728            // Performance
     1729            'nopaging'               => true,
     1730            'suppress_filters'       => true,
    17301731            'update_post_term_cache' => false,
    17311732            'update_post_meta_cache' => false,
    17321733            'ignore_sticky_posts'    => true,
    1733             'no_found_rows'          => true,
    1734             'nopaging'               => true
     1734            'no_found_rows'          => true
    17351735        ) );
    17361736        $reply_count = ! empty( $query->posts ) ? count( $query->posts ) : 0;
     
    21372137        'update_post_meta_cache' => false,
    21382138        'ignore_sticky_posts'    => true,
    2139         'no_found_rows'          => true,
    2140         'nopaging'               => true
     2139        'no_found_rows'          => true
    21412140    ) );
    21422141    $reply_id = array_shift( $query->posts );
     
    22732272    // Note that we get all post statuses here
    22742273    $topics = new WP_Query( array(
    2275         'fields'           => 'id=>parent',
    2276         'suppress_filters' => true,
    2277 
    2278         // What and how
    2279         'post_type'        => bbp_get_topic_post_type(),
    2280         'post_parent'      => $forum_id,
    2281         'post_status'      => array_keys( get_post_stati() ),
    2282         'posts_per_page'   => -1,
     2274        'fields'         => 'id=>parent',
     2275        'post_type'      => bbp_get_topic_post_type(),
     2276        'post_parent'    => $forum_id,
     2277        'post_status'    => array_keys( get_post_stati() ),
     2278        'posts_per_page' => -1,
    22832279
    22842280        // Performance
     2281        'nopaging'               => true,
     2282        'suppress_filters'       => true,
     2283        'update_post_term_cache' => false,
     2284        'update_post_meta_cache' => false,
    22852285        'ignore_sticky_posts'    => true,
    2286         'no_found_rows'          => true,
    2287         'nopaging'               => true,
    2288         'update_post_term_cache' => false,
    2289         'update_post_meta_cache' => false
     2286        'no_found_rows'          => true
    22902287    ) );
    22912288
     
    23302327    // Forum is being trashed, so its topics (and replies) are trashed too
    23312328    $topics = new WP_Query( array(
    2332         'fields'           => 'id=>parent',
    2333         'suppress_filters' => true,
    2334         'post_type'        => bbp_get_topic_post_type(),
    2335         'post_parent'      => $forum_id,
    2336         'post_status'      => $post_stati,
    2337         'posts_per_page'   => -1,
     2329        'fields'         => 'id=>parent',
     2330        'post_type'      => bbp_get_topic_post_type(),
     2331        'post_parent'    => $forum_id,
     2332        'post_status'    => $post_stati,
     2333        'posts_per_page' => -1,
    23382334
    23392335        // Performance
     2336        'nopaging'               => true,
     2337        'suppress_filters'       => true,
     2338        'update_post_term_cache' => false,
     2339        'update_post_meta_cache' => false,
    23402340        'ignore_sticky_posts'    => true,
    2341         'no_found_rows'          => true,
    2342         'nopaging'               => true,
    2343         'update_post_term_cache' => false,
    2344         'update_post_meta_cache' => false
     2341        'no_found_rows'          => true
    23452342    ) );
    23462343
Note: See TracChangeset for help on using the changeset viewer.