Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use wp_cache_flush_runtime() when available #2915

Merged
merged 8 commits into from
Aug 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions includes/classes/IndexHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1073,10 +1073,26 @@ protected function should_skip_object_index( $object, $indexable ) {
* Resets some values to reduce memory footprint.
*/
protected function stop_the_insanity() {
global $wpdb, $wp_object_cache, $wp_actions, $wp_filter;
global $wpdb, $wp_object_cache, $wp_actions;

$wpdb->queries = [];

/*
* Runtime flushing was introduced in WordPress 6.0 and will flush only the
* in-memory cache for persistent object caches
*/
if ( function_exists( 'wp_cache_flush_runtime' ) ) {
wp_cache_flush_runtime();
} else {
/*
* In the case where we're not using an external object cache, we need to call flush on the default
* WordPress object cache class to clear the values from the cache property
*/
if ( ! wp_using_ext_object_cache() ) {
wp_cache_flush();
}
}

if ( is_object( $wp_object_cache ) ) {
$wp_object_cache->group_ops = [];
$wp_object_cache->stats = [];
Expand All @@ -1093,14 +1109,6 @@ protected function stop_the_insanity() {
// No need to catch.
}

/*
* In the case where we're not using an external object cache, we need to call flush on the default
* WordPress object cache class to clear the values from the cache property
*/
if ( ! wp_using_ext_object_cache() ) {
wp_cache_flush();
}

if ( is_callable( $wp_object_cache, '__remoteset' ) ) {
call_user_func( [ $wp_object_cache, '__remoteset' ] );
}
Expand All @@ -1114,6 +1122,14 @@ protected function stop_the_insanity() {
// It's high memory consuming as WP_Query instance holds all query results inside itself
// and in theory $wp_filter will not stop growing until Out Of Memory exception occurs.
remove_filter( 'get_term_metadata', [ wp_metadata_lazyloader(), 'lazyload_term_meta' ] );

/**
* Fires after reducing the memory footprint
*
* @since 4.3.0
* @hook ep_stop_the_insanity
*/
do_action( 'ep_stop_the_insanity' );
}

/**
Expand Down