Changeset 55747
- Timestamp:
- 05/11/2023 11:13:10 AM (19 months ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-metadata-lazyloader.php
r55608 r55747 62 62 'callback' => array( $this, 'lazyload_meta_callback' ), 63 63 ), 64 'blog' => array( 65 'filter' => 'get_blog_metadata', 66 'callback' => array( $this, 'lazyload_meta_callback' ), 67 ), 64 68 ); 65 69 } -
trunk/src/wp-includes/class-wp-site-query.php
r55526 r55747 389 389 $site_ids = array_map( 'intval', $site_ids ); 390 390 391 if ( $this->query_vars['update_site_meta_cache'] ) { 392 wp_lazyload_site_meta( $site_ids ); 393 } 394 391 395 if ( 'ids' === $this->query_vars['fields'] ) { 392 396 $this->sites = $site_ids; … … 397 401 // Prime site network caches. 398 402 if ( $this->query_vars['update_site_cache'] ) { 399 _prime_site_caches( $site_ids, $this->query_vars['update_site_meta_cache']);403 _prime_site_caches( $site_ids, false ); 400 404 } 401 405 -
trunk/src/wp-includes/ms-site.php
r55702 r55747 341 341 * @since 5.1.0 Introduced the `$update_meta_cache` parameter. 342 342 * @since 6.1.0 This function is no longer marked as "private". 343 * @since 6.3.0 Use wp_lazyload_site_meta() for lazy-loading of site meta. 343 344 * 344 345 * @see update_site_cache() … … 355 356 $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared 356 357 357 update_site_cache( $fresh_sites, $update_meta_cache ); 358 } 358 update_site_cache( $fresh_sites, false ); 359 } 360 361 if ( $update_meta_cache ) { 362 wp_lazyload_site_meta( $ids ); 363 } 364 } 365 366 /** 367 * Queue site meta for lazy-loading. 368 * 369 * @since 6.3.0 370 * 371 * @param array $site_ids List of site IDs. 372 */ 373 function wp_lazyload_site_meta( array $site_ids ) { 374 if ( empty( $site_ids ) ) { 375 return; 376 } 377 $lazyloader = wp_metadata_lazyloader(); 378 $lazyloader->queue_objects( 'blog', $site_ids ); 359 379 } 360 380 -
trunk/src/wp-includes/user.php
r55703 r55747 1005 1005 if ( ! empty( $site_ids ) ) { 1006 1006 $args = array( 1007 'number' => '', 1008 'site__in' => $site_ids, 1009 'update_site_meta_cache' => false, 1007 'number' => '', 1008 'site__in' => $site_ids, 1010 1009 ); 1011 1010 if ( ! $all ) { -
trunk/tests/phpunit/includes/abstract-testcase.php
r55741 r55747 282 282 $lazyloader->reset_queue( 'term' ); 283 283 $lazyloader->reset_queue( 'comment' ); 284 $lazyloader->reset_queue( 'blog' ); 284 285 } 285 286 -
trunk/tests/phpunit/tests/multisite/siteMeta.php
r55745 r55747 249 249 $num_queries = get_num_queries(); 250 250 get_site_meta( self::$site_id, 'foo', true ); 251 $this->assertSame( $num_queries, get_num_queries() ); 251 $this->assertSame( 1, get_num_queries() - $num_queries ); 252 } 253 254 /** 255 * @ticket 58185 256 */ 257 public function test_lazy_load_site_meta() { 258 if ( ! is_site_meta_supported() ) { 259 $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' ); 260 } 261 262 $filter = new MockAction(); 263 add_filter( 'update_blog_metadata_cache', array( $filter, 'filter' ), 10, 2 ); 264 265 $q = new WP_Site_Query( 266 array( 267 'ID' => self::$site_id, 268 ) 269 ); 270 271 $this->assertSameSets( array( (string) self::$site_id ), wp_list_pluck( $q->sites, 'blog_id' ), 'Site query should return the first test site' ); 272 273 $q = new WP_Site_Query( 274 array( 275 'ID' => self::$site_id2, 276 ) 277 ); 278 279 $this->assertSameSets( array( (string) self::$site_id2 ), wp_list_pluck( $q->sites, 'blog_id' ), 'Site query should return the second test site' ); 280 281 get_site_meta( self::$site_id2 ); 282 283 $args = $filter->get_args(); 284 $first = reset( $args ); 285 $site_ids = end( $first ); 286 $this->assertSameSets( $site_ids, array( self::$site_id, self::$site_id2 ), 'This should have two site\'s meta' ); 287 } 288 289 /** 290 * @ticket 58185 291 */ 292 public function test_lazy_load_site_meta_fields_id() { 293 if ( ! is_site_meta_supported() ) { 294 $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' ); 295 } 296 297 $filter = new MockAction(); 298 add_filter( 'update_blog_metadata_cache', array( $filter, 'filter' ), 10, 2 ); 299 300 $q = new WP_Site_Query( 301 array( 302 'ID' => self::$site_id, 303 'fields' => 'ids', 304 ) 305 ); 306 307 $this->assertSameSets( array( self::$site_id ), $q->sites, 'Site query should return the first test site' ); 308 309 $q = new WP_Site_Query( 310 array( 311 'ID' => self::$site_id2, 312 'fields' => 'ids', 313 ) 314 ); 315 316 $this->assertSameSets( array( self::$site_id2 ), $q->sites, 'Site query should return the second test site' ); 317 318 get_site_meta( self::$site_id2 ); 319 320 $args = $filter->get_args(); 321 $first = reset( $args ); 322 $site_ids = end( $first ); 323 $this->assertSameSets( $site_ids, array( self::$site_id, self::$site_id2 ), 'This should have two sites meta' ); 252 324 } 253 325 … … 268 340 $num_queries = get_num_queries(); 269 341 get_site_meta( self::$site_id, 'foo', true ); 270 $this->assertSame( $num_queries + 1, get_num_queries());342 $this->assertSame( 1, get_num_queries() - $num_queries ); 271 343 } 272 344
Note: See TracChangeset
for help on using the changeset viewer.