Make WordPress Core


Ignore:
Timestamp:
02/17/2016 10:51:01 PM (9 years ago)
Author:
azaozz
Message:

Improve the performance of wp_upload_dir():

  • Cache the output in non-persistent cache.
  • Cache the result from wp_mkdir_p() in persistent cache (when present).
  • Introduce wp_get_upload_dir() for use when not uploading files. It is equivalent to wp_upload_dir() but does not check for the existence or create the upload directory.
  • Change tests to use the non-cached _wp_upload_dir(). They change options on the fly (should never be used in production) to simulate different environments.
  • Introduce _upload_dir_no_subdir() and _upload_dir_https() to facilitate testing. These use the proper upload_dir filter to simulate different environments.

Props kovshenin, azaozz.
See #34359.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r36240 r36565  
    896896        global $_wp_additional_image_sizes;
    897897
    898         // Save the current setting for uploads folders
    899         $uploads_use_yearmonth_folders = get_option( 'uploads_use_yearmonth_folders' );
    900 
    901898        // Disable date organized uploads
    902         update_option( 'uploads_use_yearmonth_folders', 0 );
     899        add_filter( 'upload_dir', '_upload_dir_no_subdir' );
    903900
    904901        // Make an image.
     
    938935        // Remove the attachment
    939936        wp_delete_attachment( $id );
    940 
    941         // Leave the uploads option the way you found it.
    942         update_option( 'uploads_use_yearmonth_folders', $uploads_use_yearmonth_folders );
     937        remove_filter( 'upload_dir', '_upload_dir_no_subdir' );
    943938    }
    944939
Note: See TracChangeset for help on using the changeset viewer.