Make WordPress Core

Changeset 56522


Ignore:
Timestamp:
09/06/2023 10:01:39 AM (11 months ago)
Author:
spacedmonkey
Message:

Database: Add expiration for dirsize_cache to transient to improve performance.

The transient dirsize_cache stores an array of directory sizes. This transient can grow very large, if the plugin directory has lots of sub directories in it. For example, a site with 30 plugins, the transient was around 2MB. For sites without a persistent object cache, transients without an expiration, are stored in autoloaded options. This means this option would load on every page request. Loading this option on every page request when it is not used it wasteful. Adding a expiration to this transient means it will not autoload. To ensure there is no degradation in performance, the expiration was set to a generous 10-year timeframe, making it highly unlikely to expire before it's refreshed.

Props nicomollet, spacedmonkey, flixos90, wpgurudev.
Fixes #54221.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r56514 r56522  
    86018601    // Only write the transient on the top level call and not on recursive calls.
    86028602    if ( $save_cache ) {
    8603         set_transient( 'dirsize_cache', $directory_cache );
     8603        $expiration = ( wp_using_ext_object_cache() ) ? 0 : 10 * YEAR_IN_SECONDS;
     8604        set_transient( 'dirsize_cache', $directory_cache, $expiration );
    86048605    }
    86058606
     
    86368637    }
    86378638
     8639    $expiration = ( wp_using_ext_object_cache() ) ? 0 : 10 * YEAR_IN_SECONDS;
    86388640    if (
    86398641        ! str_contains( $path, '/' ) &&
     
    86418643    ) {
    86428644        unset( $directory_cache[ $path ] );
    8643         set_transient( 'dirsize_cache', $directory_cache );
     8645        set_transient( 'dirsize_cache', $directory_cache, $expiration );
    86448646        return;
    86458647    }
     
    86608662    }
    86618663
    8662     set_transient( 'dirsize_cache', $directory_cache );
     8664    set_transient( 'dirsize_cache', $directory_cache, $expiration );
    86638665}
    86648666
Note: See TracChangeset for help on using the changeset viewer.