From 37e599fb3ebe4452009cc598fd8783261b7e3b3b Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 30 May 2023 14:34:22 +0000 Subject: [PATCH] Upgrade/Install: Avoid an extra database query in `populate_network()`. This moves the query for user ID of the new network's administrator closer to where the value is actually used. Includes removing unnecessary `get_userdata()` call, as user ID is the only data needed here. Follow-up to [12756], [35575], [43628]. Props nihar007, sakibmd, mukesh27, costdev, SergeyBiryukov. Fixes #58423. Built from https://develop.svn.wordpress.org/trunk@55869 git-svn-id: http://core.svn.wordpress.org/trunk@55381 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/schema.php | 27 +++++++++++++-------------- wp-includes/version.php | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index ceb1011462..8cb50fe971 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -1044,18 +1044,6 @@ function populate_network( $network_id = 1, $domain = '', $email = '', $site_nam ) ); - $site_user = get_userdata( - (int) $wpdb->get_var( - $wpdb->prepare( - "SELECT meta_value - FROM $wpdb->sitemeta - WHERE meta_key = %s AND site_id = %d", - 'admin_user_id', - $network_id - ) - ) - ); - /* * When upgrading from single to multisite, assume the current site will * become the main site of the network. When using populate_network() @@ -1079,8 +1067,19 @@ function populate_network( $network_id = 1, $domain = '', $email = '', $site_nam ) ); $current_site->blog_id = $wpdb->insert_id; - update_user_meta( $site_user->ID, 'source_domain', $domain ); - update_user_meta( $site_user->ID, 'primary_blog', $current_site->blog_id ); + + $site_user_id = (int) $wpdb->get_var( + $wpdb->prepare( + "SELECT meta_value + FROM $wpdb->sitemeta + WHERE meta_key = %s AND site_id = %d", + 'admin_user_id', + $network_id + ) + ); + + update_user_meta( $site_user_id, 'source_domain', $domain ); + update_user_meta( $site_user_id, 'primary_blog', $current_site->blog_id ); // Unable to use update_network_option() while populating the network. $wpdb->insert( diff --git a/wp-includes/version.php b/wp-includes/version.php index 61ae0aae76..c372554156 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-55868'; +$wp_version = '6.3-alpha-55869'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.