Make WordPress Core

Ticket #35791: 35791-cachefound.diff

File 35791-cachefound.diff, 1.6 KB (added by spacedmonkey, 9 years ago)
  • src/wp-includes/class-wp-site-query.php

     
    275275                $this->site_count = count( $this->sites );
    276276
    277277                if ( $site_ids && $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) {
    278                         /**
    279                          * Filters the query used to retrieve found site count.
    280                          *
    281                          * @since 4.6.0
    282                          *
    283                          * @param string        $found_sites_query SQL query. Default 'SELECT FOUND_ROWS()'.
    284                          * @param WP_Site_Query $site_query        The `WP_Site_Query` instance.
    285                          */
    286                         $found_sites_query = apply_filters( 'found_sites_query', 'SELECT FOUND_ROWS()', $this );
     278                        $found_sites_cache_key = "found_sites_query:$key:$last_changed";
     279                        $found_sites = wp_cache_get( $found_sites_cache_key, 'sites' );
     280                        if ( false === $found_sites ) {
     281                                /**
     282                                 * Filters the query used to retrieve found site count.
     283                                 *
     284                                 * @since 4.6.0
     285                                 *
     286                                 * @param string $found_sites_query SQL query. Default 'SELECT FOUND_ROWS()'.
     287                                 * @param WP_Site_Query $site_query The `WP_Site_Query` instance.
     288                                 */
     289                                $found_sites_query = apply_filters( 'found_sites_query', 'SELECT FOUND_ROWS()', $this );
     290                                $found_sites       = (int) $wpdb->get_var( $found_sites_query );
     291                                wp_cache_add( $found_sites_cache_key, $found_sites, 'sites' );
     292                        }
    287293
    288                         $this->found_sites = (int) $wpdb->get_var( $found_sites_query );
     294                        $this->found_sites   = $found_sites;
    289295                        $this->max_num_pages = ceil( $this->found_sites / $this->query_vars['number'] );
    290296                }
    291297