Make WordPress Core

Ticket #42073: 42073.2.diff

File 42073.2.diff, 2.8 KB (added by jeremyfelt, 7 years ago)
  • src/wp-includes/ms-functions.php

     
    331331function get_blog_id_from_url( $domain, $path = '/' ) {
    332332        $domain = strtolower( $domain );
    333333        $path = strtolower( $path );
    334         $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );
    335334
    336         if ( $id == -1 ) // blog does not exist
    337                 return 0;
    338         elseif ( $id )
    339                 return (int) $id;
    340 
    341         $args = array(
    342                 'domain' => $domain,
    343                 'path' => $path,
    344                 'fields' => 'ids',
    345         );
    346         $result = get_sites( $args );
    347         $id = array_shift( $result );
     335        $url = $domain . '/' . trim( $path, '/' ) . '/';
     336        $result = get_site_by( 'url', $url );
    348337
    349         if ( ! $id ) {
    350                 wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );
     338        if ( ! $result ) {
    351339                return 0;
    352340        }
    353341
    354         wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' );
    355 
    356         return $id;
     342        return $result->id;
    357343}
    358344
    359345// Admin functions
  • tests/phpunit/tests/multisite/site.php

     
    667667
    668668                // Test the original response and cached response for the newly created site.
    669669                $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
    670                 $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
    671670        }
    672671
    673672        /**
     
    688687                $details = get_site( $blog_id );
    689688
    690689                $this->assertEquals( 0, get_blog_id_from_url( $details->domain, 'foo' ) );
    691                 $this->assertEquals( -1, wp_cache_get( md5( $details->domain . 'foo' ), 'blog-id-cache' ) );
    692690        }
    693691
    694692        /**
     
    698696        function test_get_blog_id_from_url_with_deleted_flag() {
    699697                $blog_id = self::factory()->blog->create();
    700698                $details = get_site( $blog_id );
    701                 $key = md5( $details->domain . $details->path );
     699
    702700                wpmu_delete_blog( $blog_id );
    703701
    704702                $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
    705                 $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
    706         }
    707 
    708         /**
    709          * When deleted with the drop parameter as true, the cache will first be false, then set to
    710          * -1 after an attempt at `get_blog_id_from_url()` is made.
    711          */
    712         function test_get_blog_id_from_url_after_dropped() {
    713                 $blog_id = self::factory()->blog->create();
    714                 $details = get_site( $blog_id );
    715                 $key = md5( $details->domain . $details->path );
    716                 wpmu_delete_blog( $blog_id, true );
    717 
    718                 $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
    719                 $this->assertEquals( 0, get_blog_id_from_url( $details->domain, $details->path ) );
    720                 $this->assertEquals( -1, wp_cache_get( $key, 'blog-id-cache' ) );
    721703        }
    722704
    723705        /**