[wp-trac] [WordPress Trac] #34359: Cache output of `wp_upload_dir()` to improve performance

WordPress Trac noreply at wordpress.org
Tue Nov 10 00:37:15 UTC 2015


#34359: Cache output of `wp_upload_dir()` to improve performance
-------------------------------------------------+-------------------------
 Reporter:  DH-Shredder                          |       Owner:  DH-
     Type:  defect (bug)                         |  Shredder
 Priority:  normal                               |      Status:  assigned
Component:  Media                                |   Milestone:  4.4
 Severity:  normal                               |     Version:
 Keywords:  has-patch needs-testing needs-unit-  |  Resolution:
  tests                                          |     Focuses:  multisite,
                                                 |  performance
-------------------------------------------------+-------------------------

Comment (by azaozz):

 Caching the output from `wp_upload_dir()` has to be tied to the optional
 `$time` param. When it is used, the `subdir` key in the return array can
 vary. In 34359.patch the cache key also contains the year/month portion
 from `$time`.

 The cache is in the default bucket which is changed when switch_to_blog()
 runs.

 We want to cache the $uploads array (that contains all the data) before
 the `'upload_dir` filter. However there is a test (`wp_mkdir_p(
 $filtered_path )`) if the uploads sub-directories exist after that filter.
 We don't want to run this test every time as it is slow. To do that a
 second cache key is used to hold the paths that have been tested and the
 eventual error messages if creating the upload sub-directories has failed.

 There are several options used in calculating the upload path and URL.
 Currently my only concern is that in theory caching can fail if a plugin
 intercepts one of these options and returns different values depending on
 some external factor, instead of using the `upload_dir` filter.

 More testing especially on older multisite installs and with plugins like
 BuddyPress will be very appreciated.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34359#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list