Make WordPress Core


Ignore:
Timestamp:
10/16/2017 10:28:52 PM (7 years ago)
Author:
flixos90
Message:

Multisite: Revert [41719].

While get_site_by() makes sense as a more explicit and less complex replacement for get_blog_details(), it is not ready yet in terms of caching, where it currently falls short of the older function under specific circumstances.

See #40180, #40228.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/site.php

    r41719 r41883  
    119119        $details = get_blog_details( $blog_id, false );
    120120
    121         $cached_details = wp_cache_get( $blog_id, 'sites' );
    122         $this->assertNotFalse( $cached_details );
    123         $this->assertEqualSets( get_object_vars( $details ), get_object_vars( $cached_details ) );
     121        // Combine domain and path for a site specific cache key.
     122        $key = md5( $details->domain . $details->path );
     123
     124        $this->assertEquals( $details, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
    124125
    125126        // get_blogaddress_by_name()
    126127        $this->assertEquals( 'http://' . $details->domain . $details->path, get_blogaddress_by_name( trim( $details->path, '/' ) ) );
    127128
    128         // This is empty until get_blog_details() is called with $get_all = true
    129         $this->assertEquals( false, wp_cache_get( $blog_id, 'site-details' ) );
     129        // These are empty until get_blog_details() is called with $get_all = true
     130        $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
     131        $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
    130132
    131133        // $get_all = true, populate the full blog-details cache and the blog slug lookup cache
    132134        $details = get_blog_details( $blog_id, true );
    133         $cached_details = wp_cache_get( $blog_id, 'site-details' );
    134         $this->assertNotFalse( $cached_details );
    135         $this->assertEqualSets( get_object_vars( $details ), get_object_vars( $cached_details ) );
     135        $this->assertEquals( $details, wp_cache_get( $blog_id, 'blog-details' ) );
     136        $this->assertEquals( $details, wp_cache_get( $key, 'blog-lookup' ) );
    136137
    137138        // Check existence of each database table for the created site.
     
    196197        wpmu_delete_blog( $blog_id, false );
    197198
    198         $this->assertEquals( false, wp_cache_get( $blog_id, 'sites' ) );
    199         $this->assertEquals( false, wp_cache_get( $blog_id, 'site-details' ) );
     199        $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
     200        $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
     201        $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
    200202        $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
    201203    }
     
    233235        wpmu_delete_blog( $blog_id, true );
    234236
    235         $this->assertEquals( false, wp_cache_get( $blog_id, 'sites' ) );
    236         $this->assertEquals( false, wp_cache_get( $blog_id, 'site-details' ) );
     237        $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
     238        $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
     239        $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
    237240        $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
    238241    }
     
    270273        wpmu_delete_blog( $blog_id, true );
    271274
    272         $this->assertEquals( false, wp_cache_get( $blog_id, 'sites' ) );
    273         $this->assertEquals( false, wp_cache_get( $blog_id, 'site-details' ) );
     275        $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
     276        $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
     277        $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
    274278        $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
    275279    }
     
    387391        get_blog_details( $blog_id );
    388392
    389         // When the cache is primed with an invalid site, the value is not set.
    390         $this->assertFalse( wp_cache_get( $blog_id, 'site-details' ) );
     393        // When the cache is primed with an invalid site, the value is set to -1.
     394        $this->assertEquals( -1, wp_cache_get( $blog_id, 'blog-details' ) );
    391395
    392396        // Create a site in the invalid site's place.
     
    394398
    395399        // When a new site is created, its cache is cleared through refresh_blog_details.
    396         $this->assertFalse( wp_cache_get( $blog_id, 'site-details' )  );
     400        $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' )  );
    397401
    398402        $blog = get_blog_details( $blog_id );
    399403
    400404        // When the cache is refreshed, it should now equal the site data.
    401         $cached_blog = wp_cache_get( $blog_id, 'site-details' );
    402         $this->assertNotFalse( $cached_blog );
    403         $this->assertEqualSets( get_object_vars( $blog ), get_object_vars( $cached_blog ) );
     405        $this->assertEquals( $blog, wp_cache_get( $blog_id, 'blog-details' ) );
    404406    }
    405407
Note: See TracChangeset for help on using the changeset viewer.