diff --git a/wp-includes/class-wp-metadata-lazyloader.php b/wp-includes/class-wp-metadata-lazyloader.php index fa2067c5c2..f9c02391d2 100644 --- a/wp-includes/class-wp-metadata-lazyloader.php +++ b/wp-includes/class-wp-metadata-lazyloader.php @@ -61,6 +61,10 @@ class WP_Metadata_Lazyloader { 'filter' => 'get_comment_metadata', 'callback' => array( $this, 'lazyload_meta_callback' ), ), + 'blog' => array( + 'filter' => 'get_blog_metadata', + 'callback' => array( $this, 'lazyload_meta_callback' ), + ), ); } diff --git a/wp-includes/class-wp-site-query.php b/wp-includes/class-wp-site-query.php index c9b96280a5..6435ac02e1 100644 --- a/wp-includes/class-wp-site-query.php +++ b/wp-includes/class-wp-site-query.php @@ -388,6 +388,10 @@ class WP_Site_Query { $site_ids = array_map( 'intval', $site_ids ); + if ( $this->query_vars['update_site_meta_cache'] ) { + wp_lazyload_site_meta( $site_ids ); + } + if ( 'ids' === $this->query_vars['fields'] ) { $this->sites = $site_ids; @@ -396,7 +400,7 @@ class WP_Site_Query { // Prime site network caches. if ( $this->query_vars['update_site_cache'] ) { - _prime_site_caches( $site_ids, $this->query_vars['update_site_meta_cache'] ); + _prime_site_caches( $site_ids, false ); } // Fetch full site objects from the primed cache. diff --git a/wp-includes/ms-site.php b/wp-includes/ms-site.php index 90cf484049..486fad2414 100644 --- a/wp-includes/ms-site.php +++ b/wp-includes/ms-site.php @@ -340,6 +340,7 @@ function get_site( $site = null ) { * @since 4.6.0 * @since 5.1.0 Introduced the `$update_meta_cache` parameter. * @since 6.1.0 This function is no longer marked as "private". + * @since 6.3.0 Use wp_lazyload_site_meta() for lazy-loading of site meta. * * @see update_site_cache() * @global wpdb $wpdb WordPress database abstraction object. @@ -354,8 +355,27 @@ function _prime_site_caches( $ids, $update_meta_cache = true ) { if ( ! empty( $non_cached_ids ) ) { $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 - update_site_cache( $fresh_sites, $update_meta_cache ); + update_site_cache( $fresh_sites, false ); } + + if ( $update_meta_cache ) { + wp_lazyload_site_meta( $ids ); + } +} + +/** + * Queue site meta for lazy-loading. + * + * @since 6.3.0 + * + * @param array $site_ids List of site IDs. + */ +function wp_lazyload_site_meta( array $site_ids ) { + if ( empty( $site_ids ) ) { + return; + } + $lazyloader = wp_metadata_lazyloader(); + $lazyloader->queue_objects( 'blog', $site_ids ); } /** diff --git a/wp-includes/user.php b/wp-includes/user.php index 8f70f2a739..0669a052d0 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -1004,9 +1004,8 @@ function get_blogs_of_user( $user_id, $all = false ) { if ( ! empty( $site_ids ) ) { $args = array( - 'number' => '', - 'site__in' => $site_ids, - 'update_site_meta_cache' => false, + 'number' => '', + 'site__in' => $site_ids, ); if ( ! $all ) { $args['archived'] = 0; diff --git a/wp-includes/version.php b/wp-includes/version.php index 81d885aa77..ba566197bc 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-55746'; +$wp_version = '6.3-alpha-55747'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.