Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/05/2012 05:32:33 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Performance:

  • Add 'numeric' to applicable meta-queries to avoid casting as char.
  • Remove meta-queries, and use post_parent where possible.
  • Introduce _bbp_has_replies_where() filter, attached to 'posts_where' which is responsible for adding the lead topic to the results. This avoids having to use a costly meta-query, potentially resulting in full table scans.
  • Audit meta-queries, and tweak where needed.
  • Fixes #1885.
  • Props vibol for investigation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-forum-functions.php

    r4042 r4059  
    15691569
    15701570    // Setup arrays
    1571     $retval = $private = $hidden = $meta_query = $forum_ids = array();
    1572 
     1571    $private = $hidden = $meta_query = $forum_ids = array();
     1572
     1573    // Default return value
     1574    switch ( $type ) {
     1575        case 'string' :
     1576            $retval = '';
     1577            break;
     1578
     1579        case 'array'  :
     1580            $retval = array();
     1581            break;
     1582
     1583        case 'meta_query' :
     1584            $retval = array( array() ) ;
     1585            break;
     1586    }
     1587   
    15731588    // Exclude for everyone but super admins
    15741589    if ( !is_super_admin() ) {
     
    16051620                        'key'     => '_bbp_forum_id',
    16061621                        'value'   => implode( ',', $forum_ids ),
     1622                        'type'    => 'numeric',
    16071623                        'compare' => ( 1 < count( $forum_ids ) ) ? 'NOT IN' : '!='
    16081624                    );
     
    19491965    // Validate forum ID
    19501966    $forum_id = bbp_get_forum_id( $forum_id );
    1951 
    19521967    if ( empty( $forum_id ) )
    19531968        return;
     
    19561971    if ( bbp_has_topics( array(
    19571972        'post_type'      => bbp_get_topic_post_type(),
     1973        'post_parent'    => $forum_id,
    19581974        'post_status'    => 'any',
    1959         'posts_per_page' => -1,
    1960         'meta_query'     => array( array(
    1961             'key'        => '_bbp_forum_id',
    1962             'value'      => $forum_id,
    1963             'compare'    => '='
    1964         ) )
     1975        'posts_per_page' => -1
    19651976    ) ) ) {
    19661977        while ( bbp_topics() ) {
     
    19932004    // Validate forum ID
    19942005    $forum_id = bbp_get_forum_id( $forum_id );
    1995 
    19962006    if ( empty( $forum_id ) )
    19972007        return;
     
    20072017    if ( bbp_has_topics( array(
    20082018        'post_type'      => bbp_get_topic_post_type(),
     2019        'post_parent'    => $forum_id,
    20092020        'post_status'    => $post_stati,
    2010         'posts_per_page' => -1,
    2011         'meta_query'     => array( array(
    2012             'key'        => '_bbp_forum_id',
    2013             'value'      => $forum_id,
    2014             'compare'    => '='
    2015         ) )
     2021        'posts_per_page' => -1
    20162022    ) ) ) {
    20172023
Note: See TracChangeset for help on using the changeset viewer.