Make WordPress Core


Ignore:
Timestamp:
05/11/2023 11:13:10 AM (12 months ago)
Author:
spacedmonkey
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-site.php

    r55702 r55747  
    341341 * @since 5.1.0 Introduced the `$update_meta_cache` parameter.
    342342 * @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.
    343344 *
    344345 * @see update_site_cache()
     
    355356        $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
    356357
    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 */
     373function 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 );
    359379}
    360380
Note: See TracChangeset for help on using the changeset viewer.