mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-12-06 12:51:58 +00:00
Multisite: Improve get_blog_details() by using get_site_by().
`get_site_by()` is now the preferred way to retrieve a site object by lookup for identifying data. By using a coherent structure and `get_sites()` internally, it has several advantages over the direct database queries and complex code in `get_blog_details()`. Therefore `get_blog_details()` is now a wrapper for `get_site_by()`, providing backward compatibility fixes where necessary. Unit tests have been adjusted to account for the `blog-details` and `blog-lookup` cache groups, which are no longer needed. Props spacedmonkey, jeremyfelt, flixos90. Fixes #40228. git-svn-id: https://develop.svn.wordpress.org/trunk@41719 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -118,22 +118,21 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
|
||||
// $get_all = false, only retrieve details from the blogs table
|
||||
$details = get_blog_details( $blog_id, false );
|
||||
|
||||
// Combine domain and path for a site specific cache key.
|
||||
$key = md5( $details->domain . $details->path );
|
||||
|
||||
$this->assertEquals( $details, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
|
||||
$cached_details = wp_cache_get( $blog_id, 'sites' );
|
||||
$this->assertNotFalse( $cached_details );
|
||||
$this->assertEqualSets( get_object_vars( $details ), get_object_vars( $cached_details ) );
|
||||
|
||||
// get_blogaddress_by_name()
|
||||
$this->assertEquals( 'http://' . $details->domain . $details->path, get_blogaddress_by_name( trim( $details->path, '/' ) ) );
|
||||
|
||||
// These are empty until get_blog_details() is called with $get_all = true
|
||||
$this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
|
||||
// This is empty until get_blog_details() is called with $get_all = true
|
||||
$this->assertEquals( false, wp_cache_get( $blog_id, 'site-details' ) );
|
||||
|
||||
// $get_all = true, populate the full blog-details cache and the blog slug lookup cache
|
||||
$details = get_blog_details( $blog_id, true );
|
||||
$this->assertEquals( $details, wp_cache_get( $blog_id, 'blog-details' ) );
|
||||
$this->assertEquals( $details, wp_cache_get( $key, 'blog-lookup' ) );
|
||||
$cached_details = wp_cache_get( $blog_id, 'site-details' );
|
||||
$this->assertNotFalse( $cached_details );
|
||||
$this->assertEqualSets( get_object_vars( $details ), get_object_vars( $cached_details ) );
|
||||
|
||||
// Check existence of each database table for the created site.
|
||||
foreach ( $wpdb->tables( 'blog', false ) as $table ) {
|
||||
@@ -196,9 +195,8 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
|
||||
// Delete the site without forcing a table drop.
|
||||
wpmu_delete_blog( $blog_id, false );
|
||||
|
||||
$this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $blog_id, 'sites' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $blog_id, 'site-details' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
|
||||
}
|
||||
|
||||
@@ -234,9 +232,8 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
|
||||
// Delete the site and force a table drop.
|
||||
wpmu_delete_blog( $blog_id, true );
|
||||
|
||||
$this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $blog_id, 'sites' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $blog_id, 'site-details' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
|
||||
}
|
||||
|
||||
@@ -272,9 +269,8 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
|
||||
// Delete the site and force a table drop.
|
||||
wpmu_delete_blog( $blog_id, true );
|
||||
|
||||
$this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $blog_id, 'sites' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $blog_id, 'site-details' ) );
|
||||
$this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
|
||||
}
|
||||
|
||||
@@ -390,19 +386,21 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
|
||||
// Prime the cache for an invalid site.
|
||||
get_blog_details( $blog_id );
|
||||
|
||||
// When the cache is primed with an invalid site, the value is set to -1.
|
||||
$this->assertEquals( -1, wp_cache_get( $blog_id, 'blog-details' ) );
|
||||
// When the cache is primed with an invalid site, the value is not set.
|
||||
$this->assertFalse( wp_cache_get( $blog_id, 'site-details' ) );
|
||||
|
||||
// Create a site in the invalid site's place.
|
||||
self::factory()->blog->create();
|
||||
|
||||
// When a new site is created, its cache is cleared through refresh_blog_details.
|
||||
$this->assertFalse( wp_cache_get( $blog_id, 'blog-details' ) );
|
||||
$this->assertFalse( wp_cache_get( $blog_id, 'site-details' ) );
|
||||
|
||||
$blog = get_blog_details( $blog_id );
|
||||
|
||||
// When the cache is refreshed, it should now equal the site data.
|
||||
$this->assertEquals( $blog, wp_cache_get( $blog_id, 'blog-details' ) );
|
||||
$cached_blog = wp_cache_get( $blog_id, 'site-details' );
|
||||
$this->assertNotFalse( $cached_blog );
|
||||
$this->assertEqualSets( get_object_vars( $blog ), get_object_vars( $cached_blog ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,25 +27,6 @@ class Tests_Multisite_Site_Details extends WP_UnitTestCase {
|
||||
$this->assertFalse( $cached_result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_whitelisted_options
|
||||
*
|
||||
* @ticket 40063
|
||||
*/
|
||||
public function test_update_whitelisted_option_deletes_blog_details_cache( $whitelisted_option, $temporary_value ) {
|
||||
$blog_details = get_blog_details();
|
||||
|
||||
$original_value = $blog_details->$whitelisted_option;
|
||||
update_option( $whitelisted_option, $temporary_value );
|
||||
|
||||
$cached_result = wp_cache_get( $blog_details->id, 'blog-details' );
|
||||
|
||||
/* Reset to original value. */
|
||||
update_option( $whitelisted_option, $original_value );
|
||||
|
||||
$this->assertFalse( $cached_result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_whitelisted_options
|
||||
*
|
||||
@@ -65,25 +46,6 @@ class Tests_Multisite_Site_Details extends WP_UnitTestCase {
|
||||
$this->assertNotFalse( $cached_result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_whitelisted_options
|
||||
*
|
||||
* @ticket 40063
|
||||
*/
|
||||
public function test_update_whitelisted_option_does_not_delete_short_blog_details_cache( $whitelisted_option, $temporary_value ) {
|
||||
$blog_details = get_blog_details( null, false );
|
||||
|
||||
$original_value = get_option( $whitelisted_option );
|
||||
update_option( $whitelisted_option, $temporary_value );
|
||||
|
||||
$cached_result = wp_cache_get( $blog_details->id . 'short', 'blog-details' );
|
||||
|
||||
/* Reset to original value. */
|
||||
update_option( $whitelisted_option, $original_value );
|
||||
|
||||
$this->assertNotFalse( $cached_result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_whitelisted_options
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user