Make WordPress Core

Ticket #15170: 15170.2.diff

File 15170.2.diff, 1.7 KB (added by ryan, 14 years ago)

Show latest x sites with no paging if on a large network

  • wp-admin/includes/list-table-sites.php

     
    3232                $s = isset( $_REQUEST['s'] ) ? stripslashes( trim( $_REQUEST[ 's' ] ) ) : '';
    3333                $like_s = esc_sql( like_escape( $s ) );
    3434
     35                $large_network = false;
     36                // If the network is large and a search is not being performed, show only the latest blogs with no paging in order
     37                // to avoid expensive count queries.
     38                if ( !$s && ( get_blog_count() >= 10000 ) ) {
     39                        if ( !isset($_REQUEST['orderby']) )
     40                                $_GET['orderby'] = $_REQUEST['orderby'] = 'registered';
     41                        if ( !isset($_REQUEST['order']) )
     42                                $_GET['order'] = $_REQUEST['order'] = 'DESC';
     43                        $large_network = true;
     44                }
     45
    3546                $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
    3647
    3748                if ( isset( $_REQUEST['searchaction'] ) ) {
     
    6374                $order = ( isset( $_REQUEST['order'] ) && 'DESC' == strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC";
    6475                $query .= $order;
    6576
    66                 $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) );
     77                // Don't do an unbounded count on large networks
     78                if ( ! $large_network )
     79                        $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) );
    6780
    6881                $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page );
    6982                $this->items = $wpdb->get_results( $query, ARRAY_A );
    7083
     84                if ( $large_network )
     85                        $total = count($this->items);
     86
    7187                $this->set_pagination_args( array(
    7288                        'total_items' => $total,
    7389                        'per_page' => $per_page,