Ticket #42252: 42252.2.diff
File 42252.2.diff, 3.6 KB (added by , 6 years ago) |
---|
-
src/wp-includes/class-wp-site-query.php
229 229 * or the number of sites when 'count' is passed as a query var. 230 230 */ 231 231 public function get_sites() { 232 $query_vars = $this->query_vars; 232 233 $this->parse_query(); 233 234 234 235 /** … … 240 241 */ 241 242 do_action_ref_array( 'pre_get_sites', array( &$this ) ); 242 243 243 // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. 244 $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ); 244 $cache_key = $this->get_cache_key( $query_vars ); 245 245 246 // Ignore the $fields argument as the queried result will be the same regardless.247 unset( $_args['fields'] );248 249 $key = md5( serialize( $_args ) );250 $last_changed = wp_cache_get_last_changed( 'sites' );251 252 $cache_key = "get_sites:$key:$last_changed";253 246 $cache_value = wp_cache_get( $cache_key, 'sites' ); 254 247 255 248 if ( false === $cache_value ) { … … 315 308 return $this->sites; 316 309 } 317 310 311 312 protected function get_cache_key( $query_vars = '' ) { 313 if ( empty( $query_vars ) ) { 314 $query_vars = $this->query_vars; 315 } 316 317 $query_vars_key = array_keys( $query_vars ); 318 $search = array( 'domain', 'path', 'network_id', 'number' ); 319 $diff = array_diff( $query_vars_key, $search ); 320 321 if ( $query_vars['number'] == 1 && count( $diff ) == 0 ) { 322 $_args = array(); 323 array_pop( $search ); 324 foreach ( $search as $element ) { 325 if ( empty( $query_vars[ $element ] ) ) { 326 break; 327 } 328 $_args[] = $query_vars[ $element ]; 329 } 330 $key = md5( serialize( $_args ) ); 331 $cache_key = "get_sites:$key"; 332 } else { 333 // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. 334 $_args = wp_array_slice_assoc( $query_vars, array_keys( $this->query_var_defaults ) ); 335 336 // Ignore the $fields argument as the queried result will be the same regardless. 337 unset( $_args['fields'] ); 338 339 // Ignore the $update_site_cache as it does not affect the query. 340 unset( $_args['update_site_cache'] ); 341 $key = md5( serialize( ksort( $_args ) ) ); 342 $last_changed = wp_cache_get_last_changed( 'sites' ); 343 $cache_key = "get_sites:$key:$last_changed"; 344 } 345 346 return $cache_key; 347 } 348 318 349 /** 319 350 * Used internally to get a list of site IDs matching the query vars. 320 351 * -
src/wp-includes/ms-blogs.php
444 444 445 445 // Make sure a WP_Site object exists even when the site has been deleted. 446 446 $blog = new WP_Site( (object) array( 447 'blog_id' => $blog_id, 448 'domain' => null, 449 'path' => null, 447 'blog_id' => $blog_id, 448 'domain' => null, 449 'path' => null, 450 'network_id' => get_current_network_id() 450 451 ) ); 451 452 } 452 453 … … 462 463 wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' ); 463 464 wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' ); 464 465 466 467 $list = array( 'domain', 'path', 'network_id' ); 468 $_args = array(); 469 foreach ( $list as $element ) { 470 $_args[] = $blog->$element; 471 $key = md5( serialize( $_args ) ); 472 $cache_key = "get_sites:$key"; 473 wp_cache_delete( $cache_key, 'sites' ); 474 } 475 465 476 /** 466 477 * Fires immediately after a site has been removed from the object cache. 467 478 *