-
Notifications
You must be signed in to change notification settings - Fork 101
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
Add Site Health test for Object Caching #1301
base: trunk
Are you sure you want to change the base?
Add Site Health test for Object Caching #1301
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
* Helper functions used for Object Cache Support Info. | ||
* | ||
* @package performance-lab | ||
* @since 2.1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @since 2.1.0 | |
* @since n.e.x.t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
* Callback for Object Cache Info fields. | ||
* | ||
* @return array Fields. | ||
* @since 3.3.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @since 3.3.0 | |
* @since n.e.x.t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
'value' => wp_cache_supports( 'get_multiple' ) ? 'Enabled' : 'Disabled', | ||
), | ||
'multiple_sets' => array( | ||
'label' => __( 'Multiple sets', 'performance-lab' ), | ||
'value' => wp_cache_supports( 'set_multiple' ) ? 'Enabled' : 'Disabled', | ||
), | ||
'multiple_deletes' => array( | ||
'label' => __( 'Multiple deletes', 'performance-lab' ), | ||
'value' => wp_cache_supports( 'delete_multiple' ) ? 'Enabled' : 'Disabled', | ||
), | ||
'flush_group' => array( | ||
'label' => __( 'Flush group', 'performance-lab' ), | ||
'value' => wp_cache_supports( 'flush_group' ) ? 'Enabled' : 'Disabled', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't Enabled
and Disabled
be translated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
* @return string | ||
* @since 3.3.0 | ||
*/ | ||
function wp_get_cache_type() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need a Performance Lab prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
* problems with this function's ability to determine which object cache is being used. | ||
* | ||
* @return string | ||
* @since 3.3.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @since 3.3.0 | |
* @since n.e.x.t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
* @return array Fields. | ||
* @since 3.3.0 | ||
*/ | ||
function object_cache_supported_fields() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function needs the Performance Lab prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
* | ||
* @param array $info Site Health Info. | ||
* | ||
* @return array Amended Info. | ||
* @since 3.3.0 | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* | |
* @param array $info Site Health Info. | |
* | |
* @return array Amended Info. | |
* @since 3.3.0 | |
* | |
* | |
* @since n.e.x.t | |
* | |
* @param array<string, mixed> $info Site Health Info. | |
* @return array<string, mixed> Amended Info. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
* @since 3.3.0 | ||
* | ||
*/ | ||
function object_cache_supported_info( array $info ): array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs Performance Lab prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
* Hook callbacks used for Site Health Info. | ||
* | ||
* @package performance-lab | ||
* @since 2.1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @since 2.1.0 | |
* @since n.e.x.t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@mkurdybanowski Hi! Are you planning to pick this up again? |
Hi @westonruter, yes, should be able to work on it next week! |
* @param array{object_cache: array{label: string,description: string,fields: array<string, array{label: string,value: string}>}} $info Site Health Info. | ||
* | ||
* @return array{object_cache: array{label: string,description: string,fields: array<string, array{label: string,value: string}>}} Amended Info. | ||
* @since n.e.x.t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The typing can be made a bit more generic.
* @param array{object_cache: array{label: string,description: string,fields: array<string, array{label: string,value: string}>}} $info Site Health Info. | |
* | |
* @return array{object_cache: array{label: string,description: string,fields: array<string, array{label: string,value: string}>}} Amended Info. | |
* @since n.e.x.t | |
* @since n.e.x.t | |
* | |
* @param array<string, array{label: string, description: string, fields: array<string, array{label: string, value: string}>}> $info Site Health Info. | |
* @return array<string, array{label: string, description: string, fields: array<string, array{label: string, value: string}>}> Amended Info. | |
* |
/** | ||
* Adds Object Cache module to Site Health Info. | ||
* | ||
* @param array{object_cache: array{label: string,description: string,fields: array<string, array{label: string,value: string}>}} $info Site Health Info. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The object_cache
key wouldn't exist yet in the $info
being passed in.
} | ||
|
||
// Test for Xcache object cache (https://plugins.svn.wordpress.org/xcache/trunk/object-cache.php). | ||
} elseif ( $wp_object_cache instanceof \XCache_Object_Cache ) { // @phpstan-ignore-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What specifically is being ignored for PHPStan on this line? The specific error identifier should be used here to prevent ignoring something unintentionally.
} elseif ( $wp_object_cache instanceof \XCache_Object_Cache ) { // @phpstan-ignore-line | |
} elseif ( $wp_object_cache instanceof XCache_Object_Cache ) { // @phpstan-ignore-line |
} elseif ( isset( $wp_object_cache->mc ) ) { | ||
$is_memcache = true; | ||
foreach ( $wp_object_cache->mc as $bucket ) { | ||
if ( ! $bucket instanceof \Memcache && ! $bucket instanceof \Memcached ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ( ! $bucket instanceof \Memcache && ! $bucket instanceof \Memcached ) { | |
if ( ! $bucket instanceof Memcache && ! $bucket instanceof Memcached ) { |
|
||
if ( ! empty( $_wp_using_ext_object_cache ) ) { | ||
// Test for Memcached PECL extension memcached object cache (https://github.com/tollmanz/wordpress-memcached-backend). | ||
if ( isset( $wp_object_cache->m ) && $wp_object_cache->m instanceof \Memcached ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're not using namespaces, the \
an be removed.
if ( isset( $wp_object_cache->m ) && $wp_object_cache->m instanceof \Memcached ) { | |
if ( isset( $wp_object_cache->m ) && $wp_object_cache->m instanceof Memcached ) { |
$message = 'APC'; | ||
|
||
// Test for WP Redis (https://wordpress.org/plugins/wp-redis/). | ||
} elseif ( isset( $wp_object_cache->redis ) && $wp_object_cache->redis instanceof \Redis ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} elseif ( isset( $wp_object_cache->redis ) && $wp_object_cache->redis instanceof \Redis ) { | |
} elseif ( isset( $wp_object_cache->redis ) && $wp_object_cache->redis instanceof Redis ) { |
$message = 'Redis'; | ||
|
||
// Test for WP LCache Object cache (https://github.com/lcache/wp-lcache). | ||
} elseif ( isset( $wp_object_cache->lcache ) && $wp_object_cache->lcache instanceof \LCache\Integrated ) { // @phpstan-ignore-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What specifically is being ignored for PHPStan on this line? The specific error identifier should be used here to prevent ignoring something unintentionally.
} elseif ( isset( $wp_object_cache->lcache ) && $wp_object_cache->lcache instanceof \LCache\Integrated ) { // @phpstan-ignore-line | |
} elseif ( isset( $wp_object_cache->lcache ) && $wp_object_cache->lcache instanceof \Cache\Integrated ) { // @phpstan-ignore-line |
* | ||
* @return array<string, array{label: string, value: string}> Fields. | ||
* @since n.e.x.t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* | |
* @return array<string, array{label: string, value: string}> Fields. | |
* @since n.e.x.t | |
* | |
* @since n.e.x.t | |
* | |
* @return array<string, array{label: string, value: string}> Fields. |
* | ||
* @link https://github.com/wp-cli/wp-cli/blob/0ca6d920123ac904c918d69181edc5071dc92c9d/php/utils-wp.php#L259-L331. | ||
* | ||
* @global bool $_wp_using_ext_object_cache Whether external object cache is being used. | ||
* @global WP_Object_Cache $wp_object_cache Object cache global instance. | ||
* | ||
* @return string Object cache type. | ||
* @since n.e.x.t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically the @since
goes among the first tags.
* | |
* @link https://github.com/wp-cli/wp-cli/blob/0ca6d920123ac904c918d69181edc5071dc92c9d/php/utils-wp.php#L259-L331. | |
* | |
* @global bool $_wp_using_ext_object_cache Whether external object cache is being used. | |
* @global WP_Object_Cache $wp_object_cache Object cache global instance. | |
* | |
* @return string Object cache type. | |
* @since n.e.x.t | |
* | |
* @since n.e.x.t | |
* @link https://github.com/wp-cli/wp-cli/blob/0ca6d920123ac904c918d69181edc5071dc92c9d/php/utils-wp.php#L259-L331. | |
* | |
* @global WP_Object_Cache $wp_object_cache Object cache global instance. | |
* | |
* @return string Object cache type. |
This also removes the $_wp_using_ext_object_cache
per below.
global $_wp_using_ext_object_cache, $wp_object_cache; | ||
|
||
$message = ''; | ||
|
||
if ( ! empty( $_wp_using_ext_object_cache ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per #1219 let's avoid using empty()
here. And it seems we can avoid using the $_wp_using_ext_object_cache
private global by instead just using the wp_using_ext_object_cache()
function:
global $_wp_using_ext_object_cache, $wp_object_cache; | |
$message = ''; | |
if ( ! empty( $_wp_using_ext_object_cache ) ) { | |
global $wp_object_cache; | |
$message = ''; | |
if ( wp_using_ext_object_cache() ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@westonruter will fix mentioned issues after 12 of August, as I just started holidays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Enjoy!
Summary
Fixes #718
Relevant technical choices