Making WordPress.org

Changeset 3851


Ignore:
Timestamp:
08/24/2016 01:15:18 PM (5 years ago)
Author:
jmdodd
Message:

Support: Improve performance of forum and large view resultsets.

We can sort by post id because we don't edit dates on forum topics.

File:
1 edited

Legend:

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

    r3846 r3851  
    2222            if ( ! in_array( $view, array( 'plugin', 'theme', 'review' ) ) ) {
    2323                $r['date_query'] = array( 'after' => '19 months ago' );
     24            } else {
     25                $term = self::get_term();
     26
     27                // If there are a lot of results for a single plugin or theme,
     28                // order by ID to avoid an INNER JOIN ON.
     29                if ( $term && ! is_wp_error( $term ) && property_exists( $term, 'count' ) ) {
     30                    if ( $term->count > 10000 ) {
     31                        unset( $r['meta_key'] );
     32                        unset( $r['meta_type'] );
     33
     34                        $r['orderby'] = 'ID';
     35                    }
     36                }
    2437            }
    2538
     
    3548            unset( $r['meta_type'] );
    3649
    37             $r['orderby'] = 'post_date';
     50            // This only works because we don't edit dates on forum topics.
     51            $r['orderby'] = 'ID';
    3852            add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ) );
    3953        }
     
    7185        return $r;
    7286    }
     87
     88    /**
     89     * Get the term for a plugin or theme view from query_var.
     90     */
     91    public static function get_term() {
     92        if ( ! empty( get_query_var( Plugin::get_instance()->plugins->query_var() ) ) ) {
     93            $slug = Plugin::get_instance()->plugins->slug();
     94            $tax  = Plugin::get_instance()->plugins->taxonomy();
     95        } elseif ( ! empty( get_query_var( Plugin::get_instance()->themes->query_var() ) ) ) {
     96            $slug = Plugin::get_instance()->themes->slug();
     97            $tax  = Plugin::get_instance()->themes->taxonomy();
     98        }
     99        $term = get_term( $slug, $tax );
     100        return $term;
     101    }
    73102}
Note: See TracChangeset for help on using the changeset viewer.