Networks and Sites: Lazy load site meta.
In [36566] a framework to lazily load metadata was introduced. This supported term and comment meta by default. In this commit, extends support for site ( blog ) meta. Site meta is not heavily used by core and is used by developers to extend multisite. In this change, `_prime_site_caches` and `WP_Site_Query` now call the new function `wp_lazyload_site_meta`. The function `wp_lazyload_site_meta` accepts an array of ids and adds them to the queue of metadata to be lazily loaded. The function `get_blogs_of_user` was updated to now lazily load site meta. Follow on from [55671]. Props spacedmonkey, johnjamesjacoby, peterwilsoncc, mukesh27. Fixes #58185. Built from https://develop.svn.wordpress.org/trunk@55747 git-svn-id: http://core.svn.wordpress.org/trunk@55259 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
041f2d982f
commit
3ac5fd72d0
|
@ -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' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue