WordPress.org

Make WordPress Core

Ticket #42573: 42573.5.patch

File 42573.5.patch, 1.4 KB (added by schlessera, 2 months ago)

Only use caching for a depth > 1, and reduce expiry to 5 minutes (updated)

  • src/wp-includes/class-wp-theme.php

    diff --git src/wp-includes/class-wp-theme.php src/wp-includes/class-wp-theme.php
    index 171d8b6c58..d577ba7a6d 100644
    final class WP_Theme implements ArrayAccess { 
    984984         *               being absolute paths. 
    985985         */ 
    986986        public function get_files( $type = null, $depth = 0, $search_parent = false ) { 
    987                 // get and cache all theme files to start with. 
    988                 $label = sanitize_key( 'files_' . $this->cache_hash . '-' . $this->get( 'Version' ) ); 
    989                 $transient_key = substr( $label, 0, 29 ) . md5( $label ); 
     987                $do_caching = $depth > 1; 
     988                $all_files  = false; 
     989 
     990                if ( $do_caching ) { 
     991                        // get and cache all theme files to start with. 
     992                        $label = sanitize_key( 'files_' . $this->cache_hash . '-' . $this->get( 'Version' ) ); 
     993                        $transient_key = substr( $label, 0, 29 ) . md5( $label ); 
     994 
     995                        $all_files = get_transient( $transient_key ); 
     996                } 
    990997 
    991                 $all_files = get_transient( $transient_key ); 
    992998                if ( false === $all_files ) { 
    993999                        $all_files = (array) self::scandir( $this->get_stylesheet_directory(), null, -1 ); 
    9941000 
    final class WP_Theme implements ArrayAccess { 
    9961002                                $all_files += (array) self::scandir( $this->get_template_directory(), null, -1 ); 
    9971003                        } 
    9981004 
    999                         set_transient( $transient_key, $all_files, HOUR_IN_SECONDS ); 
     1005                        $do_caching && set_transient( $transient_key, $all_files, 5 * MINUTE_IN_SECONDS ); 
    10001006                } 
    10011007 
    10021008                // Filter $all_files by $type & $depth.