Making WordPress.org

Changeset 3860


Ignore:
Timestamp:
08/26/2016 01:49:07 PM (9 years ago)
Author:
jmdodd
Message:

Support: Improve topic list loadtimes.

Remove Gravatar display from lists of topics; remove custom pagination and rely on SQL_CALC_FOUND_ROWS.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php

    r3851 r3860  
    66
    77    function __construct() {
     8        // Gravatar suppression on lists of topics.
     9        add_filter( 'bbp_after_get_topic_author_link_parse_args', array( __CLASS__, 'get_author_link' ) );
     10        add_filter( 'bbp_after_get_reply_author_link_parse_args', array( __CLASS__, 'get_author_link' ) );
     11
     12        // Query simplification.
    813        add_filter( 'bbp_after_has_topics_parse_args', array( __CLASS__, 'has_topics' ) );
     14    }
     15
     16    /**
     17     * Remove unnecessary Gravatar display on lists of topics.
     18     */
     19    public static function get_author_link( $r ) {
     20        if ( ! bbp_is_single_topic() || bbp_is_topic_edit() ) {
     21            $r['type'] = 'name';
     22        }
     23        return $r;
    924    }
    1025
     
    2641
    2742                // If there are a lot of results for a single plugin or theme,
    28                 // order by ID to avoid an INNER JOIN ON.
     43                // order by post_date to avoid an INNER JOIN ON.
    2944                if ( $term && ! is_wp_error( $term ) && property_exists( $term, 'count' ) ) {
    3045                    if ( $term->count > 10000 ) {
     
    3247                        unset( $r['meta_type'] );
    3348
    34                         $r['orderby'] = 'ID';
     49                        $r['orderby'] = 'post_date';
    3550                    }
    3651                }
     
    4964
    5065            // This only works because we don't edit dates on forum topics.
    51             $r['orderby'] = 'ID';
    52             add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ) );
    53         }
    54         return $r;
    55     }
    56 
    57     /**
    58      * If this is a single forum query, don't use SQL_CALC_FOUND_ROWS to find the
    59      * total available topics.
    60      */
    61     public static function pre_get_posts( $q ) {
    62         if (
    63             isset( $q->query['post_type'] ) && $q->query['post_type'] === bbp_get_topic_post_type()
    64         ) {
    65             $q->set( 'no_found_rows', true );
    66             add_filter( 'posts_groupby', '__return_empty_string' );
    67             add_filter( 'bbp_topic_pagination', array( __CLASS__, 'topic_pagination' ) );
    68         }
    69     }
    70 
    71     /**
    72      * Instead, use a COUNT(*) query to find total topics in a forum.
    73      */
    74     public static function topic_pagination( $r ) {
    75         global $wpdb;
    76 
    77         if ( bbp_is_single_forum() ) {
    78             $per_page = bbp_get_topics_per_page();
    79             $forum_id = bbp_get_forum_id();
    80             $total = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE 1=1 AND post_type = 'topic' AND post_parent = %d AND post_status IN ( 'closed', 'publish' )", $forum_id ) );
    81 
    82             $r['total'] = ceil( (int) $total / (int) $per_page );
    83             remove_filter( 'bbp_topic_pagination', array( __CLASS__, 'topic_pagination' ) );
     66            $r['orderby'] = 'post_date';
    8467        }
    8568        return $r;
Note: See TracChangeset for help on using the changeset viewer.