mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@56522 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -8600,7 +8600,8 @@ function recurse_dirsize( $directory, $exclude = null, $max_execution_time = nul
|
||||
|
||||
// Only write the transient on the top level call and not on recursive calls.
|
||||
if ( $save_cache ) {
|
||||
set_transient( 'dirsize_cache', $directory_cache );
|
||||
$expiration = ( wp_using_ext_object_cache() ) ? 0 : 10 * YEAR_IN_SECONDS;
|
||||
set_transient( 'dirsize_cache', $directory_cache, $expiration );
|
||||
}
|
||||
|
||||
return $size;
|
||||
@@ -8635,12 +8636,13 @@ function clean_dirsize_cache( $path ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$expiration = ( wp_using_ext_object_cache() ) ? 0 : 10 * YEAR_IN_SECONDS;
|
||||
if (
|
||||
! str_contains( $path, '/' ) &&
|
||||
! str_contains( $path, '\\' )
|
||||
) {
|
||||
unset( $directory_cache[ $path ] );
|
||||
set_transient( 'dirsize_cache', $directory_cache );
|
||||
set_transient( 'dirsize_cache', $directory_cache, $expiration );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8659,7 +8661,7 @@ function clean_dirsize_cache( $path ) {
|
||||
unset( $directory_cache[ $path ] );
|
||||
}
|
||||
|
||||
set_transient( 'dirsize_cache', $directory_cache );
|
||||
set_transient( 'dirsize_cache', $directory_cache, $expiration );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user