Changeset 49744
- Timestamp:
- 12/03/2020 08:37:43 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/upgrade.php
r49671 r49744 875 875 } 876 876 877 if ( $wp_current_db_version < 49 632) {877 if ( $wp_current_db_version < 49735 ) { 878 878 upgrade_560(); 879 879 } … … 2275 2275 save_mod_rewrite_rules(); 2276 2276 } 2277 2278 if ( $wp_current_db_version < 49735 ) { 2279 delete_transient( 'dirsize_cache' ); 2280 } 2277 2281 } 2278 2282 -
trunk/src/wp-includes/functions.php
r49693 r49744 7627 7627 function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null, &$directory_cache = null ) { 7628 7628 $directory = untrailingslashit( $directory ); 7629 $cache_path = untrailingslashit( str_replace( ABSPATH, '', $directory ) );7630 7631 7629 $save_cache = false; 7632 7630 … … 7636 7634 } 7637 7635 7638 if ( isset( $directory_cache[ $ cache_path] ) ) {7639 return $directory_cache[ $ cache_path];7636 if ( isset( $directory_cache[ $directory ] ) && is_int( $directory_cache[ $directory ] ) ) { 7637 return $directory_cache[ $directory ]; 7640 7638 } 7641 7639 … … 7706 7704 } 7707 7705 7708 $directory_cache[ $ cache_path] = $size;7706 $directory_cache[ $directory ] = $size; 7709 7707 7710 7708 // Only write the transient on the top level call and not on recursive calls. … … 7732 7730 } 7733 7731 7734 $ cache_path = untrailingslashit( str_replace( ABSPATH, '', $path ));7735 unset( $directory_cache[ $ cache_path ] );7736 7737 while ( DIRECTORY_SEPARATOR !== $ cache_path && '.' !== $cache_path && '..' !== $cache_path ) {7738 $ cache_path = dirname( $cache_path );7739 unset( $directory_cache[ $ cache_path ] );7732 $path = untrailingslashit( $path ); 7733 unset( $directory_cache[ $path ] ); 7734 7735 while ( DIRECTORY_SEPARATOR !== $path && '.' !== $path && '..' !== $path ) { 7736 $path = dirname( $path ); 7737 unset( $directory_cache[ $path ] ); 7740 7738 } 7741 7739 -
trunk/src/wp-includes/version.php
r49644 r49744 21 21 * @global int $wp_db_version 22 22 */ 23 $wp_db_version = 49 632;23 $wp_db_version = 49735; 24 24 25 25 /** -
trunk/tests/phpunit/tests/multisite/cleanDirsizeCache.php
r49630 r49744 94 94 95 95 $upload_dir = wp_upload_dir(); 96 $cache_key_prefix = untrailingslashit( str_replace( ABSPATH, '', $upload_dir['basedir'] ));96 $cache_key_prefix = untrailingslashit( $upload_dir['basedir'] ); 97 97 98 98 // Clear the dirsize cache. … … 142 142 143 143 $upload_dir = wp_upload_dir(); 144 $cache_key_prefix = untrailingslashit( str_replace( ABSPATH, '', $upload_dir['basedir'] ));144 $cache_key_prefix = untrailingslashit( $upload_dir['basedir'] ); 145 145 146 146 // Clear the dirsize cache. … … 206 206 207 207 // `dirsize_cache` should now be filled after upload and recurse_dirsize() call. 208 $cache_path = untrailingslashit( str_replace( ABSPATH, '', $upload_dir['path'] ));208 $cache_path = untrailingslashit( $upload_dir['path'] ); 209 209 $this->assertSame( true, is_array( get_transient( 'dirsize_cache' ) ) ); 210 210 $this->assertSame( $size, get_transient( 'dirsize_cache' )[ $cache_path ] ); … … 234 234 235 235 function _get_mock_dirsize_cache_for_site( $site_id ) { 236 $prefix = wp_upload_dir()['basedir']; 237 236 238 return array( 237 " wp-content/uploads/sites/$site_id/2/2"=> 22,238 " wp-content/uploads/sites/$site_id/2/1"=> 21,239 " wp-content/uploads/sites/$site_id/2"=> 2,240 " wp-content/uploads/sites/$site_id/1/3"=> 13,241 " wp-content/uploads/sites/$site_id/1/2"=> 12,242 " wp-content/uploads/sites/$site_id/1/1"=> 11,243 " wp-content/uploads/sites/$site_id/1"=> 1,244 " wp-content/uploads/sites/$site_id/custom_directory" => 42,239 "$prefix/2/2" => 22, 240 "$prefix/2/1" => 21, 241 "$prefix/2" => 2, 242 "$prefix/1/3" => 13, 243 "$prefix/1/2" => 12, 244 "$prefix/1/1" => 11, 245 "$prefix/1" => 1, 246 "$prefix/custom_directory" => 42, 245 247 ); 246 248 } 249 250 /* 251 * Test that 5.6+ gracefully handles the old 5.5 transient structure. 252 * 253 * @ticket 51913 254 */ 255 function test_5_5_transient_structure_compat() { 256 $blog_id = self::factory()->blog->create(); 257 switch_to_blog( $blog_id ); 258 259 /* 260 * Our comparison of space relies on an initial value of 0. If a previous test has failed 261 * or if the `src` directory already contains a directory with site content, then the initial 262 * expectation will be polluted. We create sites until an empty one is available. 263 */ 264 while ( 0 !== get_space_used() ) { 265 restore_current_blog(); 266 $blog_id = self::factory()->blog->create(); 267 switch_to_blog( $blog_id ); 268 } 269 270 // Clear the dirsize cache. 271 delete_transient( 'dirsize_cache' ); 272 273 // Set the dirsize cache to our mock. 274 set_transient( 'dirsize_cache', $this->_get_mock_5_5_dirsize_cache( $blog_id ) ); 275 276 $upload_dir = wp_upload_dir(); 277 278 /* 279 * The cached size should be ignored, because it's in the old format. The function 280 * will try to fetch a live value, but in this case the folder doesn't actually 281 * exist on disk, so the function should fail. 282 */ 283 $this->assertSame( false, recurse_dirsize( $upload_dir['basedir'] . '/2/1' ) ); 284 285 /* 286 * Now that it's confirmed that old cached values aren't being returned, create the 287 * folder on disk, so that the the rest of the function can be tested. 288 */ 289 wp_mkdir_p( $upload_dir['basedir'] . '/2/1' ); 290 $filename = $upload_dir['basedir'] . '/2/1/this-needs-to-exist.txt'; 291 file_put_contents( $filename, 'this file is 21 bytes' ); 292 293 // Clear the dirsize cache. 294 delete_transient( 'dirsize_cache' ); 295 296 // Set the dirsize cache to our mock. 297 set_transient( 'dirsize_cache', $this->_get_mock_5_5_dirsize_cache( $blog_id ) ); 298 299 /* 300 * Now that the folder exists, the old cached value should be overwritten 301 * with the size, using the current format. 302 */ 303 $this->assertSame( 21, recurse_dirsize( $upload_dir['basedir'] . '/2/1' ) ); 304 $this->assertSame( 21, get_transient( 'dirsize_cache' )[ $upload_dir['basedir'] . '/2/1' ] ); 305 306 // No cache match on non existing directory should return false. 307 $this->assertSame( false, recurse_dirsize( $upload_dir['basedir'] . '/does_not_exist' ) ); 308 309 // Cleanup. 310 $this->remove_added_uploads(); 311 rmdir( $upload_dir['basedir'] . '/2/1' ); 312 313 restore_current_blog(); 314 } 315 316 function _get_mock_5_5_dirsize_cache( $site_id ) { 317 $prefix = untrailingslashit( wp_upload_dir()['basedir'] ); 318 319 return array( 320 "$prefix/2/2" => array( 'size' => 22 ), 321 "$prefix/2/1" => array( 'size' => 21 ), 322 "$prefix/2" => array( 'size' => 2 ), 323 "$prefix/1/3" => array( 'size' => 13 ), 324 "$prefix/1/2" => array( 'size' => 12 ), 325 "$prefix/1/1" => array( 'size' => 11 ), 326 "$prefix/1" => array( 'size' => 1 ), 327 "$prefix/custom_directory" => array( 'size' => 42 ), 328 ); 329 } 247 330 } 248 331
Note: See TracChangeset
for help on using the changeset viewer.