From 3df07b17ddc92863075b046c5f34d3ab540d1d50 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Thu, 21 Apr 2016 19:58:27 +0000 Subject: [PATCH] Media: Don't cache the results of `wp_mkdir_p()` in a persistent cache. To improve the performance of `wp_upload_dir()` the result of `wp_mkdir_p()` was stored in a persistent cache, introduced in [36565]. But this becomes an issue when WordPress is scaled horizontally. You may end up caching a value for a server where the directory doesn't exist which will prevent further uploads on other servers because of the persistent cache. The fix is to use a non-persistent cache. Props azaozz, ocean90. See #34359. Fixes #36621. Built from https://develop.svn.wordpress.org/trunk@37285 git-svn-id: http://core.svn.wordpress.org/trunk@37251 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 16 ++++++---------- wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index ca1c4c91fc..1c4a445b74 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1854,7 +1854,7 @@ function wp_get_upload_dir() { * @return array See above for description. */ function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false ) { - static $cache = array(); + static $cache = array(), $tested_paths = array(); $key = sprintf( '%d-%s', get_current_blog_id(), (string) $time ); @@ -1874,13 +1874,10 @@ function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false if ( $create_dir ) { $path = $uploads['path']; - $tested_paths = wp_cache_get( 'upload_dir_tested_paths' ); - if ( ! is_array( $tested_paths ) ) { - $tested_paths = array(); - } - - if ( ! in_array( $path, $tested_paths, true ) ) { + if ( array_key_exists( $path, $tested_paths ) ) { + $uploads['error'] = $tested_paths[ $path ]; + } else { if ( ! wp_mkdir_p( $path ) ) { if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) { $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; @@ -1889,10 +1886,9 @@ function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false } $uploads['error'] = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), esc_html( $error_path ) ); - } else { - $tested_paths[] = $path; - wp_cache_set( 'upload_dir_tested_paths', $tested_paths ); } + + $tested_paths[ $path ] = $uploads['error']; } } diff --git a/wp-includes/version.php b/wp-includes/version.php index f41ccd05dd..4426069158 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-alpha-37283'; +$wp_version = '4.6-alpha-37285'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.