Ticket #45749: 45749.diff
File 45749.diff, 3.6 KB (added by , 2 years ago) |
---|
-
wp-includes/class-wp-site-query.php
88 88 public $sites; 89 89 90 90 /** 91 * List of site ids located by the query. 92 * 93 * @since 5.1.0 94 * @var array 95 */ 96 public $site_ids = null; 97 98 /** 91 99 * The amount of found sites for the current query. 92 100 * 93 101 * @since 4.6.0 … … 288 296 $this->meta_query_clauses = $this->meta_query->get_sql( 'blog', $wpdb->blogs, 'blog_id', $this ); 289 297 } 290 298 291 // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. 292 $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ); 299 if ( null === $this->site_ids ) { 293 300 294 // Ignore the $fields argument as the queried result will be the same regardless.295 unset( $_args['fields']);301 // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. 302 $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ); 296 303 297 $key = md5( serialize( $_args ) );298 $last_changed = wp_cache_get_last_changed( 'sites');304 // Ignore the $fields argument as the queried result will be the same regardless. 305 unset( $_args['fields'] ); 299 306 300 $cache_key = "get_sites:$key:$last_changed";301 $cache_value = wp_cache_get( $cache_key,'sites' );307 $key = md5( serialize( $_args ) ); 308 $last_changed = wp_cache_get_last_changed( 'sites' ); 302 309 303 if ( false === $cache_value ) { 304 $site_ids = $this->get_site_ids(); 305 if ( $site_ids ) { 306 $this->set_found_sites(); 310 $cache_key = "get_sites:$key:$last_changed"; 311 $cache_value = wp_cache_get( $cache_key, 'sites' ); 312 313 if ( false === $cache_value ) { 314 $this->site_ids = $this->get_site_ids(); 315 if ( $this->site_ids ) { 316 $this->set_found_sites(); 317 } 318 319 $cache_value = array( 320 'site_ids' => $this->site_ids, 321 'found_sites' => $this->found_sites, 322 ); 323 wp_cache_add( $cache_key, $cache_value, 'sites' ); 324 } else { 325 $this->site_ids = $cache_value['site_ids']; 326 $this->found_sites = $cache_value['found_sites']; 307 327 } 308 309 $cache_value = array(310 'site_ids' => $site_ids,311 'found_sites' => $this->found_sites,312 );313 wp_cache_add( $cache_key, $cache_value, 'sites' );314 } else {315 $site_ids = $cache_value['site_ids'];316 $this->found_sites = $cache_value['found_sites'];317 328 } 318 329 319 330 if ( $this->found_sites && $this->query_vars['number'] ) { … … 322 333 323 334 // If querying for a count only, there's nothing more to do. 324 335 if ( $this->query_vars['count'] ) { 325 // $ site_ids is actually a count in this case.326 return intval( $ site_ids );336 // $this->site_ids is actually a count in this case. 337 return intval( $this->site_ids ); 327 338 } 328 339 329 $ site_ids = array_map( 'intval', $site_ids );340 $this->site_ids = array_map( 'intval', $this->site_ids ); 330 341 331 342 if ( 'ids' == $this->query_vars['fields'] ) { 332 $this->sites = $ site_ids;343 $this->sites = $this->site_ids; 333 344 334 345 return $this->sites; 335 346 } … … 336 347 337 348 // Prime site network caches. 338 349 if ( $this->query_vars['update_site_cache'] ) { 339 _prime_site_caches( $ site_ids, $this->query_vars['update_site_meta_cache'] );350 _prime_site_caches( $this->site_ids, $this->query_vars['update_site_meta_cache'] ); 340 351 } 341 352 342 353 // Fetch full site objects from the primed cache. 343 354 $_sites = array(); 344 foreach ( $ site_ids as $site_id ) {355 foreach ( $this->site_ids as $site_id ) { 345 356 if ( $_site = get_site( $site_id ) ) { 346 357 $_sites[] = $_site; 347 358 }