Make WordPress Core


Ignore:
Timestamp:
08/09/2016 11:38:41 AM (8 years ago)
Author:
pento
Message:

Multisite: Improve performance of the upgrade page on large networks.

The query to select the next 5 blogs to upgrade was ordered by registered, which isn't indexed. This causes the query to table scan, which will be slow on networks with many blogs.

The query only needs to be ordered by something that won't change, so ordering by blog_id is a good replacement. blog_id is indexed, and it's the only column being returned, so MySQL is able to optimize for a fast index read.

Props fliespl.
Fixes #37612.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/network/upgrade.php

    r37914 r38229  
    5656        }
    5757
    58         $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A );
     58        $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY blog_id DESC LIMIT {$n}, 5", ARRAY_A );
    5959        if ( empty( $blogs ) ) {
    6060            echo '<p>' . __( 'All done!' ) . '</p>';
Note: See TracChangeset for help on using the changeset viewer.