From 2f7c8033d281bb5214e861ca853ca74ffd5ca8fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Wed, 19 Jan 2022 13:54:43 -0800 Subject: [PATCH 01/48] initial code import --- modules/object-cache/health/load.php | 103 +++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 modules/object-cache/health/load.php diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php new file mode 100644 index 0000000000..e416f13e31 --- /dev/null +++ b/modules/object-cache/health/load.php @@ -0,0 +1,103 @@ + 'persistent_object_cache', + 'test' => 'oc_health_persistent_object_cache', + ); + + return $tests; +} + +/** + * Callback for `persistent_object_cache` health check. + * + * @return array + */ +function oc_health_persistent_object_cache() { + /** + * Filter the action URL for the persistent object cache health check. + * + * @param string $action_url Learn more link for persistent object cache health check. + */ + $action_url = apply_filters( + 'site_status_persistent_object_cache_url', + /* translators: Localized Support reference. */ + __( 'https://wordpress.org/support/article/object-cache/', 'performance-lab' ) + ); + + $result = array( + 'test' => 'persistent_object_cache', + 'status' => 'good', + 'badge' => array( + 'label' => __( 'Performance', 'performance-lab' ), + 'color' => 'blue', + ), + 'description' => sprintf( + '

%s

', + __( "WordPress performs at its best when a persistent object cache is used. Persistent object caching helps to reduce load on your SQL server and allows WordPress to retrieve your site's content and settings much faster.", 'performance-lab' ) + ), + 'actions' => sprintf( + '

%s %s

', + esc_url( $action_url ), + __( 'Learn more about persistent object caching.', 'performance-lab' ), + /* translators: Accessibility text. */ + __( '(opens in a new tab)', 'performance-lab' ) + ), + ); + + if ( wp_using_ext_object_cache() ) { + $result['label'] = __( 'A persistent object cache is being used', 'performance-lab' ); + + return $result; + } + + /** + * Filter whether to suggest using a persistent object cache. + * + * @param bool $suggest + */ + if ( apply_filters( 'site_status_persistent_object_cache', false ) ) { + $result['status'] = 'recommended'; + $result['label'] = __( 'You should use a persistent object cache', 'performance-lab' ); + $result['description'] .= sprintf( + '

%s

', + __( '...', 'performance-lab' ) + ); + + return $result; + } + + $result['label'] = __( 'A persistent object cache is not required', 'performance-lab' ); + + return $result; +} + +/** + * Callback for `site_status_persistent_object_cache` filter. + * + * Determines whether to suggest using a persistent object cache. + * + * @param mixed $should_suggest Whether to suggest using a persistent object cache. + * @return bool + */ +function oc_health_should_persistent_object_cache( $should_suggest ) { + return true; +} From 348fff5c0fb7776ae09386cd9619c8932d36e658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Wed, 19 Jan 2022 17:00:42 -0800 Subject: [PATCH 02/48] use existing page; still needs section --- modules/object-cache/health/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index e416f13e31..eaf16a0e15 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -40,7 +40,7 @@ function oc_health_persistent_object_cache() { $action_url = apply_filters( 'site_status_persistent_object_cache_url', /* translators: Localized Support reference. */ - __( 'https://wordpress.org/support/article/object-cache/', 'performance-lab' ) + __( 'https://wordpress.org/support/article/optimization/#object-caching', 'performance-lab' ) ); $result = array( From b6a1cc30178899321083a68088c5fc4b153c476a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Wed, 19 Jan 2022 17:01:13 -0800 Subject: [PATCH 03/48] add some basic criteria --- modules/object-cache/health/load.php | 59 +++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index eaf16a0e15..636e5e8151 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -99,5 +99,62 @@ function oc_health_persistent_object_cache() { * @return bool */ function oc_health_should_persistent_object_cache( $should_suggest ) { - return true; + global $wpdb; + + $threshold_alloptions_count = 500; + $threshold_alloptions_bytes = 100000; + $threshold_comments_count = 1000; + $threshold_options_count = 1000; + $threshold_posts_count = 1000; + $threshold_terms_count = 1000; + $threshold_users_count = 1000; + + $alloptions = wp_load_alloptions(); + + if ( $threshold_alloptions_count < count( $alloptions ) ) { + return true; + } + + if ( $threshold_alloptions_bytes < strlen( serialize( wp_load_alloptions() ) ) ) { + return true; + } + + $table_names = implode( "','", array( $wpdb->comments, $wpdb->options, $wpdb->posts, $wpdb->terms, $wpdb->users ) ); + + // With InnoDB the `TABLE_ROWS` are estimates, which are accurate enough + // and faster to retrieve than individual `COUNT()` queries + $results = $wpdb->get_results( + $wpdb->prepare( + "SELECT TABLE_NAME AS 'table', TABLE_ROWS AS 'rows', SUM(data_length + index_length) as 'bytes' + FROM information_schema.TABLES + WHERE TABLE_SCHEMA = %s + AND TABLE_NAME IN ('$table_names') + GROUP BY TABLE_NAME; + ", + DB_NAME + ), + OBJECT_K + ); + + if ( $threshold_comments_count < $results[ $wpdb->comments ]->rows ) { + return true; + } + + if ( $threshold_options_count < $results[ $wpdb->options ]->rows ) { + return true; + } + + if ( $threshold_posts_count < $results[ $wpdb->posts ]->rows ) { + return true; + } + + if ( $threshold_terms_count < $results[ $wpdb->terms ]->rows ) { + return true; + } + + if ( $threshold_users_count < $results[ $wpdb->users ]->rows ) { + return true; + } + + return false; } From 60d38629c93e1c571f84c8f86a036ede48229ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 20 Jan 2022 14:22:42 -0800 Subject: [PATCH 04/48] make it easy to add a thresholds filter later on --- modules/object-cache/health/load.php | 30 +++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 636e5e8151..07440cdf3d 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -101,21 +101,23 @@ function oc_health_persistent_object_cache() { function oc_health_should_persistent_object_cache( $should_suggest ) { global $wpdb; - $threshold_alloptions_count = 500; - $threshold_alloptions_bytes = 100000; - $threshold_comments_count = 1000; - $threshold_options_count = 1000; - $threshold_posts_count = 1000; - $threshold_terms_count = 1000; - $threshold_users_count = 1000; + $thresholds = array( + 'alloptions_count' => 1, + 'alloptions_bytes' => 100000, + 'comments_count' => 1000, + 'options_count' => 1000, + 'posts_count' => 1000, + 'terms_count' => 1000, + 'users_count' => 1000, + ); $alloptions = wp_load_alloptions(); - if ( $threshold_alloptions_count < count( $alloptions ) ) { + if ( $thresholds['alloptions_count'] < count( $alloptions ) ) { return true; } - if ( $threshold_alloptions_bytes < strlen( serialize( wp_load_alloptions() ) ) ) { + if ( $thresholds['alloptions_bytes'] < strlen( serialize( wp_load_alloptions() ) ) ) { return true; } @@ -136,23 +138,23 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { OBJECT_K ); - if ( $threshold_comments_count < $results[ $wpdb->comments ]->rows ) { + if ( $thresholds['comments_count'] < $results[ $wpdb->comments ]->rows ) { return true; } - if ( $threshold_options_count < $results[ $wpdb->options ]->rows ) { + if ( $thresholds['options_count'] < $results[ $wpdb->options ]->rows ) { return true; } - if ( $threshold_posts_count < $results[ $wpdb->posts ]->rows ) { + if ( $thresholds['posts_count'] < $results[ $wpdb->posts ]->rows ) { return true; } - if ( $threshold_terms_count < $results[ $wpdb->terms ]->rows ) { + if ( $thresholds['terms_count'] < $results[ $wpdb->terms ]->rows ) { return true; } - if ( $threshold_users_count < $results[ $wpdb->users ]->rows ) { + if ( $thresholds['users_count'] < $results[ $wpdb->users ]->rows ) { return true; } From 889444628dd5c5f71d5ce9fa58dff5ac5c784a0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 20 Jan 2022 14:23:05 -0800 Subject: [PATCH 05/48] please the formatting gods --- modules/object-cache/health/load.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 07440cdf3d..9c0c470201 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -123,16 +123,16 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { $table_names = implode( "','", array( $wpdb->comments, $wpdb->options, $wpdb->posts, $wpdb->terms, $wpdb->users ) ); - // With InnoDB the `TABLE_ROWS` are estimates, which are accurate enough - // and faster to retrieve than individual `COUNT()` queries + // With InnoDB the `TABLE_ROWS` are estimates, which are accurate enough and faster to retrieve than individual `COUNT()` queries. $results = $wpdb->get_results( $wpdb->prepare( + // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared "SELECT TABLE_NAME AS 'table', TABLE_ROWS AS 'rows', SUM(data_length + index_length) as 'bytes' FROM information_schema.TABLES WHERE TABLE_SCHEMA = %s AND TABLE_NAME IN ('$table_names') - GROUP BY TABLE_NAME; - ", + GROUP BY TABLE_NAME;", + // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared DB_NAME ), OBJECT_K From 234c048cfe6c338a9c2a8da6ead7f67860fe5171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 20 Jan 2022 15:10:47 -0800 Subject: [PATCH 06/48] detect object cache services --- modules/object-cache/health/load.php | 43 ++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 9c0c470201..d0eef24f4c 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -74,18 +74,22 @@ function oc_health_persistent_object_cache() { * * @param bool $suggest */ - if ( apply_filters( 'site_status_persistent_object_cache', false ) ) { - $result['status'] = 'recommended'; - $result['label'] = __( 'You should use a persistent object cache', 'performance-lab' ); - $result['description'] .= sprintf( - '

%s

', - __( '...', 'performance-lab' ) - ); + if ( ! apply_filters( 'site_status_persistent_object_cache', false ) ) { + $result['label'] = __( 'A persistent object cache is not required', 'performance-lab' ); return $result; } - $result['label'] = __( 'A persistent object cache is not required', 'performance-lab' ); + $available_services = oc_health_available_persistent_object_cache_services(); + + $description = sprintf( + __( 'Your host appears to support the following object cache services: %s. Speak to your web host about what persistent object cache services are available and how to enable them.', 'performance-lab' ), + implode( ', ', $available_services ) + ); + + $result['status'] = 'recommended'; + $result['label'] = __( 'You should use a persistent object cache', 'performance-lab' ); + $result['description'] .= sprintf( '

%s

', $description ); return $result; } @@ -160,3 +164,26 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { return false; } + +/** + * Returns a list of available persistent object cache services. + * + * @return array The list of available persistent object cache services. + */ +function oc_health_available_persistent_object_cache_services() { + $extensions = array_map( 'extension_loaded', array( + 'Redis' => 'redis', + 'Relay' => 'relay', + 'Memcached' => 'memcache', // The `memcached` extension seems unmaintained + 'APCu' => 'apcu', + ) ); + + $services = array_keys( array_filter( $extensions ) ); + + /** + * Filter the persistent object cache services available to the user. + * + * @param array $suggest + */ + return apply_filters( 'site_status_available_object_cache_services', $services ); +} From ae1d6f7500eecc0354f34157b73c024db4bb8385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 20 Jan 2022 15:12:12 -0800 Subject: [PATCH 07/48] please the gods again --- modules/object-cache/health/load.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index d0eef24f4c..dc7a1ec0b2 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -83,7 +83,8 @@ function oc_health_persistent_object_cache() { $available_services = oc_health_available_persistent_object_cache_services(); $description = sprintf( - __( 'Your host appears to support the following object cache services: %s. Speak to your web host about what persistent object cache services are available and how to enable them.', 'performance-lab' ), + /* translators: Available object caching services. */ + __( 'Your host appears to support the following object caching services: %s. Speak to your web host about what persistent object caches are available and how to enable them.', 'performance-lab' ), implode( ', ', $available_services ) ); @@ -171,12 +172,15 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { * @return array The list of available persistent object cache services. */ function oc_health_available_persistent_object_cache_services() { - $extensions = array_map( 'extension_loaded', array( - 'Redis' => 'redis', - 'Relay' => 'relay', - 'Memcached' => 'memcache', // The `memcached` extension seems unmaintained - 'APCu' => 'apcu', - ) ); + $extensions = array_map( + 'extension_loaded', + array( + 'Redis' => 'redis', + 'Relay' => 'relay', + 'Memcached' => 'memcache', // The `memcached` extension seems unmaintained. + 'APCu' => 'apcu', + ) + ); $services = array_keys( array_filter( $extensions ) ); From 4f89ffe07d802086f7b0868b01a9354d843ab1df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 20 Jan 2022 18:18:45 -0800 Subject: [PATCH 08/48] be more verbal --- modules/object-cache/health/load.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index dc7a1ec0b2..59affc0039 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -72,9 +72,11 @@ function oc_health_persistent_object_cache() { /** * Filter whether to suggest using a persistent object cache. * + * Plugin and theme authors should NOT use this filter to discourage the use of an object cache. + * * @param bool $suggest */ - if ( ! apply_filters( 'site_status_persistent_object_cache', false ) ) { + if ( ! apply_filters( 'site_status_suggest_persistent_object_cache', false ) ) { $result['label'] = __( 'A persistent object cache is not required', 'performance-lab' ); return $result; @@ -187,6 +189,8 @@ function oc_health_available_persistent_object_cache_services() { /** * Filter the persistent object cache services available to the user. * + * This can be useful to hide or add services not included in the defaults. + * * @param array $suggest */ return apply_filters( 'site_status_available_object_cache_services', $services ); From bc01b45048d2c08e4f4ba49158e79adce27c5d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 20 Jan 2022 18:19:10 -0800 Subject: [PATCH 09/48] refine 2nd part of the description --- modules/object-cache/health/load.php | 40 +++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 59affc0039..660a33a4fb 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -84,15 +84,43 @@ function oc_health_persistent_object_cache() { $available_services = oc_health_available_persistent_object_cache_services(); - $description = sprintf( - /* translators: Available object caching services. */ - __( 'Your host appears to support the following object caching services: %s. Speak to your web host about what persistent object caches are available and how to enable them.', 'performance-lab' ), - implode( ', ', $available_services ) - ); + $notes = __( 'Speak to your web host about what persistent object caches are available and how to enable them.', 'performance-lab' ); + + if ( ! empty( $available_services ) ) { + $notes .= sprintf( + /* translators: Available object caching services. */ + __( ' Your host appears to support the following object caching services: %s.', 'performance-lab' ), + implode( ', ', $available_services ) + ); + } + + /** + * Filter the second paragraph of the health check's description + * when suggesting the use of a persistent object cache. + * + * Hosts may want to replace the notes to recommend their preferred object caching solution. + * + * Plugin authors may want to append notes (not replace) on why object caching is recommended for their plugin. + * + * @param string $description + * @param array $available_services + */ + $notes = apply_filter( 'site_status_persistent_object_cache_notes', $notes, $available_services ); $result['status'] = 'recommended'; $result['label'] = __( 'You should use a persistent object cache', 'performance-lab' ); - $result['description'] .= sprintf( '

%s

', $description ); + $result['description'] .= sprintf( + '

%s

', + wp_kses( + $notes, + array( + 'a' => array( 'href' => true ), + 'code' => true, + 'em' => true, + 'strong' => true, + ) + ) + ); return $result; } From 07f12a332b03cb7472f08b5980fffff6a2435cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Fri, 21 Jan 2022 11:41:46 -0800 Subject: [PATCH 10/48] Update load.php --- modules/object-cache/health/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 660a33a4fb..f11206a666 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -152,7 +152,7 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { return true; } - if ( $thresholds['alloptions_bytes'] < strlen( serialize( wp_load_alloptions() ) ) ) { + if ( $thresholds['alloptions_bytes'] < strlen( serialize( $alloptions ) ) ) { return true; } From 24cb8699c347e0684b0a757ccf9eead42c9e3f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Fri, 21 Jan 2022 11:43:19 -0800 Subject: [PATCH 11/48] revert debug value --- modules/object-cache/health/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index f11206a666..d38ce3936e 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -137,7 +137,7 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { global $wpdb; $thresholds = array( - 'alloptions_count' => 1, + 'alloptions_count' => 500, 'alloptions_bytes' => 100000, 'comments_count' => 1000, 'options_count' => 1000, From c880585bc92e46211aa7efc165bacdf2c09c85a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Mon, 24 Jan 2022 08:35:51 -0800 Subject: [PATCH 12/48] drop the word persistent --- modules/object-cache/health/load.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index d38ce3936e..b380341529 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -82,7 +82,7 @@ function oc_health_persistent_object_cache() { return $result; } - $available_services = oc_health_available_persistent_object_cache_services(); + $available_services = oc_health_available_object_cache_services(); $notes = __( 'Speak to your web host about what persistent object caches are available and how to enable them.', 'performance-lab' ); @@ -201,7 +201,7 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { * * @return array The list of available persistent object cache services. */ -function oc_health_available_persistent_object_cache_services() { +function oc_health_available_object_cache_services() { $extensions = array_map( 'extension_loaded', array( From ce40e36e9dc9cd06cf385785d1e8b2e860fc8c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Wed, 9 Feb 2022 11:44:27 -0800 Subject: [PATCH 13/48] docblock fixes; since tags; coding standards --- modules/object-cache/health/load.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index b380341529..7df642d20f 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -8,9 +8,6 @@ * @since 1.0.0 */ -add_filter( 'site_status_tests', 'oc_health_add_tests' ); -add_filter( 'site_status_persistent_object_cache', 'oc_health_should_persistent_object_cache' ); - /** * Adds a health check testing for and suggesting a persistent object cache backend. * @@ -25,6 +22,7 @@ function oc_health_add_tests( $tests ) { return $tests; } +add_filter( 'site_status_tests', 'oc_health_add_tests' ); /** * Callback for `persistent_object_cache` health check. @@ -102,7 +100,9 @@ function oc_health_persistent_object_cache() { * * Plugin authors may want to append notes (not replace) on why object caching is recommended for their plugin. * - * @param string $description + * @since 1.0.0 + * + * @param string $notes * @param array $available_services */ $notes = apply_filter( 'site_status_persistent_object_cache_notes', $notes, $available_services ); @@ -195,6 +195,7 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { return false; } +add_filter( 'site_status_persistent_object_cache', 'oc_health_should_persistent_object_cache' ); /** * Returns a list of available persistent object cache services. @@ -219,7 +220,9 @@ function oc_health_available_object_cache_services() { * * This can be useful to hide or add services not included in the defaults. * - * @param array $suggest + * @since 1.0.0 + * + * @param array $services The list of available persistent object cache services. */ return apply_filters( 'site_status_available_object_cache_services', $services ); } From a0201f66612e306d24f1e7ca3d53829badd9a4b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Wed, 9 Feb 2022 11:48:02 -0800 Subject: [PATCH 14/48] docblocks --- modules/object-cache/health/load.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 7df642d20f..9c66581037 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -72,7 +72,7 @@ function oc_health_persistent_object_cache() { * * Plugin and theme authors should NOT use this filter to discourage the use of an object cache. * - * @param bool $suggest + * @param bool $suggest Whether to suggest using a persistent object cache. */ if ( ! apply_filters( 'site_status_suggest_persistent_object_cache', false ) ) { $result['label'] = __( 'A persistent object cache is not required', 'performance-lab' ); @@ -102,8 +102,8 @@ function oc_health_persistent_object_cache() { * * @since 1.0.0 * - * @param string $notes - * @param array $available_services + * @param string $notes The notes appended to the health check description. + * @param array $available_services The list of available persistent object cache services. */ $notes = apply_filter( 'site_status_persistent_object_cache_notes', $notes, $available_services ); From 21af1771713fe02da6a3f799d9dc2acf543bb071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Wed, 9 Feb 2022 11:55:09 -0800 Subject: [PATCH 15/48] fix filter ref --- modules/object-cache/health/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 9c66581037..2bd528a892 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -195,7 +195,7 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { return false; } -add_filter( 'site_status_persistent_object_cache', 'oc_health_should_persistent_object_cache' ); +add_filter( 'site_status_suggest_persistent_object_cache', 'oc_health_should_persistent_object_cache' ); /** * Returns a list of available persistent object cache services. From 8d2d7091eb0398bc90403a81b54646a53c9a44cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Wed, 9 Feb 2022 12:00:02 -0800 Subject: [PATCH 16/48] add more since tags --- modules/object-cache/health/load.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 2bd528a892..b951476075 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -11,6 +11,8 @@ /** * Adds a health check testing for and suggesting a persistent object cache backend. * + * @since 1.0.0 + * * @param array $tests An associative array of direct and asynchronous tests. * @return array */ @@ -27,6 +29,8 @@ function oc_health_add_tests( $tests ) { /** * Callback for `persistent_object_cache` health check. * + * @since 1.0.0 + * * @return array */ function oc_health_persistent_object_cache() { @@ -130,6 +134,8 @@ function oc_health_persistent_object_cache() { * * Determines whether to suggest using a persistent object cache. * + * @since 1.0.0 + * * @param mixed $should_suggest Whether to suggest using a persistent object cache. * @return bool */ From 02f1094b40702245dcaecc4283db10a21e37f842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Wed, 9 Feb 2022 12:00:11 -0800 Subject: [PATCH 17/48] tweak copy --- modules/object-cache/health/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index b951476075..355746e8d8 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -54,7 +54,7 @@ function oc_health_persistent_object_cache() { ), 'description' => sprintf( '

%s

', - __( "WordPress performs at its best when a persistent object cache is used. Persistent object caching helps to reduce load on your SQL server and allows WordPress to retrieve your site's content and settings much faster.", 'performance-lab' ) + __( "WordPress performs at its best when a persistent object cache is used. A persistent object cache helps to reduce load on your SQL server significantly and allows WordPress to retrieve your site's content and settings much faster.", 'performance-lab' ) ), 'actions' => sprintf( '

%s %s

', From 5f51a6f606ab4e69f7f65c6dd8c26eb0b91724a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Wed, 9 Feb 2022 12:00:19 -0800 Subject: [PATCH 18/48] fix function name --- modules/object-cache/health/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 355746e8d8..7d55ad9ad3 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -109,7 +109,7 @@ function oc_health_persistent_object_cache() { * @param string $notes The notes appended to the health check description. * @param array $available_services The list of available persistent object cache services. */ - $notes = apply_filter( 'site_status_persistent_object_cache_notes', $notes, $available_services ); + $notes = apply_filters( 'site_status_persistent_object_cache_notes', $notes, $available_services ); $result['status'] = 'recommended'; $result['label'] = __( 'You should use a persistent object cache', 'performance-lab' ); From e3bd8586fdf59682542647c0af334928539d7280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Wed, 9 Feb 2022 12:04:36 -0800 Subject: [PATCH 19/48] turn conditions into single loop --- modules/object-cache/health/load.php | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 7d55ad9ad3..5395387233 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -179,24 +179,18 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { OBJECT_K ); - if ( $thresholds['comments_count'] < $results[ $wpdb->comments ]->rows ) { - return true; - } - - if ( $thresholds['options_count'] < $results[ $wpdb->options ]->rows ) { - return true; - } - - if ( $thresholds['posts_count'] < $results[ $wpdb->posts ]->rows ) { - return true; - } - - if ( $thresholds['terms_count'] < $results[ $wpdb->terms ]->rows ) { - return true; - } + $threshold_map = array( + 'comments_count' => $wpdb->comments, + 'options_count' => $wpdb->options, + 'posts_count' => $wpdb->posts, + 'terms_count' => $wpdb->terms, + 'users_count' => $wpdb->users, + ); - if ( $thresholds['users_count'] < $results[ $wpdb->users ]->rows ) { - return true; + foreach ( $threshold_map as $threshold => $table ) { + if ( $thresholds[ $threshold ] < $results[ $table ]->rows ) { + return true; + } } return false; From af3dd69465c6021e5d3b5e4a57dc62611640cfb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Wed, 9 Feb 2022 12:12:57 -0800 Subject: [PATCH 20/48] allow easy bypass of expensive calls --- modules/object-cache/health/load.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 5395387233..97cbbab6c8 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -142,6 +142,11 @@ function oc_health_persistent_object_cache() { function oc_health_should_persistent_object_cache( $should_suggest ) { global $wpdb; + // Bypass expensive calls if `$should_suggest` was already set truthy + if ( $should_suggest ) { + return true; + } + $thresholds = array( 'alloptions_count' => 500, 'alloptions_bytes' => 100000, @@ -195,7 +200,7 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { return false; } -add_filter( 'site_status_suggest_persistent_object_cache', 'oc_health_should_persistent_object_cache' ); +add_filter( 'site_status_suggest_persistent_object_cache', 'oc_health_should_persistent_object_cache', 20 ); /** * Returns a list of available persistent object cache services. From 64e4806f3d16cee8dfff3b92e883a9916767163b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Wed, 9 Feb 2022 12:17:59 -0800 Subject: [PATCH 21/48] made thresholds filterable --- modules/object-cache/health/load.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 97cbbab6c8..2d98ccd347 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -65,6 +65,9 @@ function oc_health_persistent_object_cache() { ), ); + global $_wp_using_ext_object_cache; + $_wp_using_ext_object_cache = false; + if ( wp_using_ext_object_cache() ) { $result['label'] = __( 'A persistent object cache is being used', 'performance-lab' ); @@ -147,7 +150,14 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { return true; } - $thresholds = array( + /** + * Filter the thresholds used to determine whether to suggest the use of a persistent object cache. + * + * @since 1.0.0 + * + * @param array $thresholds The list of threshold names and numbers. + */ + $thresholds = apply_filters( 'site_status_persistent_object_cache_thresholds', array( 'alloptions_count' => 500, 'alloptions_bytes' => 100000, 'comments_count' => 1000, @@ -155,7 +165,7 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { 'posts_count' => 1000, 'terms_count' => 1000, 'users_count' => 1000, - ); + ) ); $alloptions = wp_load_alloptions(); From 6f4d1ce9c5011a5ac1b09f1e4bba57487b8724df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Wed, 9 Feb 2022 12:22:35 -0800 Subject: [PATCH 22/48] sort --- modules/object-cache/health/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 2d98ccd347..5583641111 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -221,10 +221,10 @@ function oc_health_available_object_cache_services() { $extensions = array_map( 'extension_loaded', array( + 'APCu' => 'apcu', 'Redis' => 'redis', 'Relay' => 'relay', 'Memcached' => 'memcache', // The `memcached` extension seems unmaintained. - 'APCu' => 'apcu', ) ); From 52c59ce7a7110bf6b1ca4cb3cf5b4a460dac209a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Wed, 9 Feb 2022 12:50:00 -0800 Subject: [PATCH 23/48] code styling --- modules/object-cache/health/load.php | 31 +++++++++++++++------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 5583641111..e4d61d1ae9 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -145,7 +145,7 @@ function oc_health_persistent_object_cache() { function oc_health_should_persistent_object_cache( $should_suggest ) { global $wpdb; - // Bypass expensive calls if `$should_suggest` was already set truthy + // Bypass expensive calls if `$should_suggest` was already set truthy. if ( $should_suggest ) { return true; } @@ -157,15 +157,18 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { * * @param array $thresholds The list of threshold names and numbers. */ - $thresholds = apply_filters( 'site_status_persistent_object_cache_thresholds', array( - 'alloptions_count' => 500, - 'alloptions_bytes' => 100000, - 'comments_count' => 1000, - 'options_count' => 1000, - 'posts_count' => 1000, - 'terms_count' => 1000, - 'users_count' => 1000, - ) ); + $thresholds = apply_filters( + 'site_status_persistent_object_cache_thresholds', + array( + 'alloptions_count' => 500, + 'alloptions_bytes' => 100000, + 'comments_count' => 1000, + 'options_count' => 1000, + 'posts_count' => 1000, + 'terms_count' => 1000, + 'users_count' => 1000, + ) + ); $alloptions = wp_load_alloptions(); @@ -196,10 +199,10 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { $threshold_map = array( 'comments_count' => $wpdb->comments, - 'options_count' => $wpdb->options, - 'posts_count' => $wpdb->posts, - 'terms_count' => $wpdb->terms, - 'users_count' => $wpdb->users, + 'options_count' => $wpdb->options, + 'posts_count' => $wpdb->posts, + 'terms_count' => $wpdb->terms, + 'users_count' => $wpdb->users, ); foreach ( $threshold_map as $threshold => $table ) { From 0114f3dba30e834017c36b76243ede02e18e161a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 10 Feb 2022 08:19:59 -0800 Subject: [PATCH 24/48] remove debug --- modules/object-cache/health/load.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index e4d61d1ae9..de1cdd1d0d 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -65,9 +65,6 @@ function oc_health_persistent_object_cache() { ), ); - global $_wp_using_ext_object_cache; - $_wp_using_ext_object_cache = false; - if ( wp_using_ext_object_cache() ) { $result['label'] = __( 'A persistent object cache is being used', 'performance-lab' ); From 839aad4c4e806a04a233b875b72e41611aaf17b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 10 Feb 2022 08:27:48 -0800 Subject: [PATCH 25/48] make badge orange when recommended --- modules/object-cache/health/load.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index de1cdd1d0d..1d4f542103 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -111,9 +111,10 @@ function oc_health_persistent_object_cache() { */ $notes = apply_filters( 'site_status_persistent_object_cache_notes', $notes, $available_services ); - $result['status'] = 'recommended'; - $result['label'] = __( 'You should use a persistent object cache', 'performance-lab' ); - $result['description'] .= sprintf( + $result['status'] = 'recommended'; + $result['label'] = __( 'You should use a persistent object cache', 'performance-lab' ); + $result['badge']['color'] = 'orange'; + $result['description'] .= sprintf( '

%s

', wp_kses( $notes, From afd077c861499a0582984637c6bb039d55f4c564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Fri, 11 Feb 2022 08:59:17 -0800 Subject: [PATCH 26/48] dump ci tests --- .../webp-uploads/health-check-test.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/modules/object-cache/webp-uploads/health-check-test.php diff --git a/tests/modules/object-cache/webp-uploads/health-check-test.php b/tests/modules/object-cache/webp-uploads/health-check-test.php new file mode 100644 index 0000000000..7b5f5c1098 --- /dev/null +++ b/tests/modules/object-cache/webp-uploads/health-check-test.php @@ -0,0 +1,50 @@ +assertTrue( $result ); + $this->assertTrue( $bypassed ); + } + + function test_object_cache_debug() { + global $wpdb; + + $alloptions = wp_load_alloptions(); + + var_dump(count( $alloptions )); + + var_dump(strlen( serialize( $alloptions ) )); + + $table_names = implode( "','", array( $wpdb->comments, $wpdb->options, $wpdb->posts, $wpdb->terms, $wpdb->users ) ); + + $results = $wpdb->get_results( + $wpdb->prepare( + "SELECT TABLE_NAME AS 'table', TABLE_ROWS AS 'rows', SUM(data_length + index_length) as 'bytes' + FROM information_schema.TABLES + WHERE TABLE_SCHEMA = %s + AND TABLE_NAME IN ('$table_names') + GROUP BY TABLE_NAME;", + DB_NAME + ), + OBJECT_K + ); + + var_dump($results); + } + +} From 9135d335f2f41151ef5f878be3b2895f0964fd84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Fri, 11 Feb 2022 09:13:21 -0800 Subject: [PATCH 27/48] inital tests --- .../health-check/health-check-test.php | 112 ++++++++++++++++++ .../webp-uploads/health-check-test.php | 50 -------- 2 files changed, 112 insertions(+), 50 deletions(-) create mode 100644 tests/modules/object-cache/health-check/health-check-test.php delete mode 100644 tests/modules/object-cache/webp-uploads/health-check-test.php diff --git a/tests/modules/object-cache/health-check/health-check-test.php b/tests/modules/object-cache/health-check/health-check-test.php new file mode 100644 index 0000000000..70b0ba3332 --- /dev/null +++ b/tests/modules/object-cache/health-check/health-check-test.php @@ -0,0 +1,112 @@ +assertTrue( $result ); + $this->assertTrue( $bypassed ); + + remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + } + + function test_object_cache_default_thresholds() { + $result = oc_health_should_persistent_object_cache( false ); + + $this->assertFalse( $result ); + } + + function test_object_cache_comments_threshold() { + add_filter( + 'site_status_persistent_object_cache_thresholds', + function ( $thresholds ) { + return array_merge( $thresholds, array( 'comments_count' => 0 ) ); + } + ); + + $result = oc_health_should_persistent_object_cache( false ); + + $this->assertTrue( $result ); + + remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + } + + function test_object_cache_posts_threshold() { + add_filter( + 'site_status_persistent_object_cache_thresholds', + function ( $thresholds ) { + return array_merge( $thresholds, array( 'posts_count' => 0 ) ); + } + ); + + $result = oc_health_should_persistent_object_cache( false ); + + $this->assertTrue( $result ); + + remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + } + + function test_object_cache_terms_threshold() { + add_filter( + 'site_status_persistent_object_cache_thresholds', + function ( $thresholds ) { + return array_merge( $thresholds, array( 'terms_count' => 1 ) ); + } + ); + + $result = oc_health_should_persistent_object_cache( false ); + + $this->assertTrue( $result ); + + remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + } + + function test_object_cache_options_threshold() { + add_filter( + 'site_status_persistent_object_cache_thresholds', + function ( $thresholds ) { + return array_merge( $thresholds, array( 'options_count' => 100 ) ); + } + ); + + $result = oc_health_should_persistent_object_cache( false ); + + $this->assertTrue( $result ); + + remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + } + + function test_object_cache_users_threshold() { + add_filter( + 'site_status_persistent_object_cache_thresholds', + function ( $thresholds ) { + return array_merge( $thresholds, array( 'users_count' => 1 ) ); + } + ); + + $result = oc_health_should_persistent_object_cache( false ); + + $this->assertTrue( $result ); + + remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + } + +} diff --git a/tests/modules/object-cache/webp-uploads/health-check-test.php b/tests/modules/object-cache/webp-uploads/health-check-test.php deleted file mode 100644 index 7b5f5c1098..0000000000 --- a/tests/modules/object-cache/webp-uploads/health-check-test.php +++ /dev/null @@ -1,50 +0,0 @@ -assertTrue( $result ); - $this->assertTrue( $bypassed ); - } - - function test_object_cache_debug() { - global $wpdb; - - $alloptions = wp_load_alloptions(); - - var_dump(count( $alloptions )); - - var_dump(strlen( serialize( $alloptions ) )); - - $table_names = implode( "','", array( $wpdb->comments, $wpdb->options, $wpdb->posts, $wpdb->terms, $wpdb->users ) ); - - $results = $wpdb->get_results( - $wpdb->prepare( - "SELECT TABLE_NAME AS 'table', TABLE_ROWS AS 'rows', SUM(data_length + index_length) as 'bytes' - FROM information_schema.TABLES - WHERE TABLE_SCHEMA = %s - AND TABLE_NAME IN ('$table_names') - GROUP BY TABLE_NAME;", - DB_NAME - ), - OBJECT_K - ); - - var_dump($results); - } - -} From eec2d40742345cd38dda2b5dd96305f37574333d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Fri, 11 Feb 2022 09:19:07 -0800 Subject: [PATCH 28/48] gte --- modules/object-cache/health/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 1d4f542103..ed0959753e 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -204,7 +204,7 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { ); foreach ( $threshold_map as $threshold => $table ) { - if ( $thresholds[ $threshold ] < $results[ $table ]->rows ) { + if ( $thresholds[ $threshold ] <= $results[ $table ]->rows ) { return true; } } From 38c1767734130dd62f3e63ac63e8abe0113cd23f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Fri, 11 Feb 2022 09:22:01 -0800 Subject: [PATCH 29/48] add alloptions tests --- .../health-check/health-check-test.php | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/modules/object-cache/health-check/health-check-test.php b/tests/modules/object-cache/health-check/health-check-test.php index 70b0ba3332..5d5a084d2d 100644 --- a/tests/modules/object-cache/health-check/health-check-test.php +++ b/tests/modules/object-cache/health-check/health-check-test.php @@ -98,7 +98,37 @@ function test_object_cache_users_threshold() { add_filter( 'site_status_persistent_object_cache_thresholds', function ( $thresholds ) { - return array_merge( $thresholds, array( 'users_count' => 1 ) ); + return array_merge( $thresholds, array( 'users_count' => 0 ) ); + } + ); + + $result = oc_health_should_persistent_object_cache( false ); + + $this->assertTrue( $result ); + + remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + } + + function test_object_cache_alloptions_count_threshold() { + add_filter( + 'site_status_persistent_object_cache_thresholds', + function ( $thresholds ) { + return array_merge( $thresholds, array( 'alloptions_count' => 100 ) ); + } + ); + + $result = oc_health_should_persistent_object_cache( false ); + + $this->assertTrue( $result ); + + remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + } + + function test_object_cache_alloptions_bytes_threshold() { + add_filter( + 'site_status_persistent_object_cache_thresholds', + function ( $thresholds ) { + return array_merge( $thresholds, array( 'alloptions_bytes' => 1000 ) ); } ); From aca709ad22671413391883dcf67aedd360165308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 17 Feb 2022 12:54:49 -0800 Subject: [PATCH 30/48] only run check in production --- modules/object-cache/health/load.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index ed0959753e..80ca99e037 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -17,10 +17,12 @@ * @return array */ function oc_health_add_tests( $tests ) { - $tests['direct']['persistent_object_cache'] = array( - 'label' => 'persistent_object_cache', - 'test' => 'oc_health_persistent_object_cache', - ); + if ( wp_get_environment_type() === 'production' ) { + $tests['direct']['persistent_object_cache'] = array( + 'label' => 'persistent_object_cache', + 'test' => 'oc_health_persistent_object_cache', + ); + } return $tests; } From 80d8a8c6f4561a8bdd437c38f556f56bbafe99fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 17 Feb 2022 12:58:08 -0800 Subject: [PATCH 31/48] added missing since tags --- modules/object-cache/health/load.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index 80ca99e037..cf9464b8f6 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -39,6 +39,8 @@ function oc_health_persistent_object_cache() { /** * Filter the action URL for the persistent object cache health check. * + * @since 1.0.0 + * * @param string $action_url Learn more link for persistent object cache health check. */ $action_url = apply_filters( @@ -78,6 +80,8 @@ function oc_health_persistent_object_cache() { * * Plugin and theme authors should NOT use this filter to discourage the use of an object cache. * + * @since 1.0.0 + * * @param bool $suggest Whether to suggest using a persistent object cache. */ if ( ! apply_filters( 'site_status_suggest_persistent_object_cache', false ) ) { @@ -218,6 +222,8 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { /** * Returns a list of available persistent object cache services. * + * @since 1.0.0 + * * @return array The list of available persistent object cache services. */ function oc_health_available_object_cache_services() { From 25e040cdb469ac215783741be6576c9a9940edcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 17 Feb 2022 14:21:47 -0800 Subject: [PATCH 32/48] document return values --- modules/object-cache/health/load.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health/load.php index cf9464b8f6..b97af56e72 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health/load.php @@ -14,7 +14,7 @@ * @since 1.0.0 * * @param array $tests An associative array of direct and asynchronous tests. - * @return array + * @return array An associative array of direct and asynchronous tests. */ function oc_health_add_tests( $tests ) { if ( wp_get_environment_type() === 'production' ) { @@ -33,7 +33,7 @@ function oc_health_add_tests( $tests ) { * * @since 1.0.0 * - * @return array + * @return array The health check result suggesting persistent object caching. */ function oc_health_persistent_object_cache() { /** @@ -144,7 +144,7 @@ function oc_health_persistent_object_cache() { * @since 1.0.0 * * @param mixed $should_suggest Whether to suggest using a persistent object cache. - * @return bool + * @return bool Whether to suggest using a persistent object cache. */ function oc_health_should_persistent_object_cache( $should_suggest ) { global $wpdb; From 2e3816950af4a4a1ddea778ee390c38ca51cdb3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 17 Feb 2022 14:25:42 -0800 Subject: [PATCH 33/48] update module name; rename slug --- modules/object-cache/{health => health-check}/load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename modules/object-cache/{health => health-check}/load.php (99%) diff --git a/modules/object-cache/health/load.php b/modules/object-cache/health-check/load.php similarity index 99% rename from modules/object-cache/health/load.php rename to modules/object-cache/health-check/load.php index b97af56e72..a2239f288b 100644 --- a/modules/object-cache/health/load.php +++ b/modules/object-cache/health-check/load.php @@ -1,6 +1,6 @@ Date: Thu, 17 Feb 2022 14:33:04 -0800 Subject: [PATCH 34/48] use long slug --- .../load.php | 0 .../health-check-test.php | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename modules/object-cache/{health-check => persistent-object-cache-health-check}/load.php (100%) rename tests/modules/object-cache/{health-check => persistent-object-cache-health-check}/health-check-test.php (97%) diff --git a/modules/object-cache/health-check/load.php b/modules/object-cache/persistent-object-cache-health-check/load.php similarity index 100% rename from modules/object-cache/health-check/load.php rename to modules/object-cache/persistent-object-cache-health-check/load.php diff --git a/tests/modules/object-cache/health-check/health-check-test.php b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php similarity index 97% rename from tests/modules/object-cache/health-check/health-check-test.php rename to tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php index 5d5a084d2d..dd35ba31d0 100644 --- a/tests/modules/object-cache/health-check/health-check-test.php +++ b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php @@ -1,9 +1,9 @@ Date: Thu, 17 Feb 2022 14:36:33 -0800 Subject: [PATCH 35/48] prefix functions with `perflab_oc_*` --- .../load.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/object-cache/persistent-object-cache-health-check/load.php b/modules/object-cache/persistent-object-cache-health-check/load.php index a2239f288b..bf006b3428 100644 --- a/modules/object-cache/persistent-object-cache-health-check/load.php +++ b/modules/object-cache/persistent-object-cache-health-check/load.php @@ -16,17 +16,17 @@ * @param array $tests An associative array of direct and asynchronous tests. * @return array An associative array of direct and asynchronous tests. */ -function oc_health_add_tests( $tests ) { +function perflab_oc_health_add_tests( $tests ) { if ( wp_get_environment_type() === 'production' ) { $tests['direct']['persistent_object_cache'] = array( 'label' => 'persistent_object_cache', - 'test' => 'oc_health_persistent_object_cache', + 'test' => 'perflab_oc_health_persistent_object_cache', ); } return $tests; } -add_filter( 'site_status_tests', 'oc_health_add_tests' ); +add_filter( 'site_status_tests', 'perflab_oc_health_add_tests' ); /** * Callback for `persistent_object_cache` health check. @@ -35,7 +35,7 @@ function oc_health_add_tests( $tests ) { * * @return array The health check result suggesting persistent object caching. */ -function oc_health_persistent_object_cache() { +function perflab_oc_health_persistent_object_cache() { /** * Filter the action URL for the persistent object cache health check. * @@ -90,7 +90,7 @@ function oc_health_persistent_object_cache() { return $result; } - $available_services = oc_health_available_object_cache_services(); + $available_services = perflab_oc_health_available_object_cache_services(); $notes = __( 'Speak to your web host about what persistent object caches are available and how to enable them.', 'performance-lab' ); @@ -146,7 +146,7 @@ function oc_health_persistent_object_cache() { * @param mixed $should_suggest Whether to suggest using a persistent object cache. * @return bool Whether to suggest using a persistent object cache. */ -function oc_health_should_persistent_object_cache( $should_suggest ) { +function perflab_oc_health_should_persistent_object_cache( $should_suggest ) { global $wpdb; // Bypass expensive calls if `$should_suggest` was already set truthy. @@ -217,7 +217,7 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { return false; } -add_filter( 'site_status_suggest_persistent_object_cache', 'oc_health_should_persistent_object_cache', 20 ); +add_filter( 'site_status_suggest_persistent_object_cache', 'perflab_oc_health_should_persistent_object_cache', 20 ); /** * Returns a list of available persistent object cache services. @@ -226,7 +226,7 @@ function oc_health_should_persistent_object_cache( $should_suggest ) { * * @return array The list of available persistent object cache services. */ -function oc_health_available_object_cache_services() { +function perflab_oc_health_available_object_cache_services() { $extensions = array_map( 'extension_loaded', array( From 3502b2821840ffb329975b2461dcdd303611db45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 17 Feb 2022 14:40:24 -0800 Subject: [PATCH 36/48] prefix all filters --- .../persistent-object-cache-health-check/load.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/object-cache/persistent-object-cache-health-check/load.php b/modules/object-cache/persistent-object-cache-health-check/load.php index bf006b3428..0813870c48 100644 --- a/modules/object-cache/persistent-object-cache-health-check/load.php +++ b/modules/object-cache/persistent-object-cache-health-check/load.php @@ -44,7 +44,7 @@ function perflab_oc_health_persistent_object_cache() { * @param string $action_url Learn more link for persistent object cache health check. */ $action_url = apply_filters( - 'site_status_persistent_object_cache_url', + 'perflab_oc_site_status_persistent_object_cache_url', /* translators: Localized Support reference. */ __( 'https://wordpress.org/support/article/optimization/#object-caching', 'performance-lab' ) ); @@ -84,7 +84,7 @@ function perflab_oc_health_persistent_object_cache() { * * @param bool $suggest Whether to suggest using a persistent object cache. */ - if ( ! apply_filters( 'site_status_suggest_persistent_object_cache', false ) ) { + if ( ! apply_filters( 'perflab_oc_site_status_suggest_persistent_object_cache', false ) ) { $result['label'] = __( 'A persistent object cache is not required', 'performance-lab' ); return $result; @@ -115,7 +115,7 @@ function perflab_oc_health_persistent_object_cache() { * @param string $notes The notes appended to the health check description. * @param array $available_services The list of available persistent object cache services. */ - $notes = apply_filters( 'site_status_persistent_object_cache_notes', $notes, $available_services ); + $notes = apply_filters( 'perflab_oc_site_status_persistent_object_cache_notes', $notes, $available_services ); $result['status'] = 'recommended'; $result['label'] = __( 'You should use a persistent object cache', 'performance-lab' ); @@ -162,7 +162,7 @@ function perflab_oc_health_should_persistent_object_cache( $should_suggest ) { * @param array $thresholds The list of threshold names and numbers. */ $thresholds = apply_filters( - 'site_status_persistent_object_cache_thresholds', + 'perflab_oc_site_status_persistent_object_cache_thresholds', array( 'alloptions_count' => 500, 'alloptions_bytes' => 100000, @@ -217,7 +217,7 @@ function perflab_oc_health_should_persistent_object_cache( $should_suggest ) { return false; } -add_filter( 'site_status_suggest_persistent_object_cache', 'perflab_oc_health_should_persistent_object_cache', 20 ); +add_filter( 'perflab_oc_site_status_suggest_persistent_object_cache', 'perflab_oc_health_should_persistent_object_cache', 20 ); /** * Returns a list of available persistent object cache services. @@ -248,5 +248,5 @@ function perflab_oc_health_available_object_cache_services() { * * @param array $services The list of available persistent object cache services. */ - return apply_filters( 'site_status_available_object_cache_services', $services ); + return apply_filters( 'perflab_oc_site_status_available_object_cache_services', $services ); } From 54409698e336c7df2ac94f7ca10509ef7cf9b1e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 17 Feb 2022 14:50:24 -0800 Subject: [PATCH 37/48] use prefixed names in tests --- .../health-check-test.php | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php index dd35ba31d0..ccc3ea87c7 100644 --- a/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php +++ b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php @@ -12,7 +12,7 @@ function test_object_cache_thresholds_check_is_bypassed() { $bypassed = true; add_filter( - 'site_status_persistent_object_cache_thresholds', + 'perflab_oc_site_status_persistent_object_cache_thresholds', function ( $thresholds ) use ( $bypassed ) { $bypassed = false; @@ -20,12 +20,12 @@ function ( $thresholds ) use ( $bypassed ) { } ); - $result = oc_health_should_persistent_object_cache( true ); + $result = perflab_oc_health_should_persistent_object_cache( true ); $this->assertTrue( $result ); $this->assertTrue( $bypassed ); - remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); } function test_object_cache_default_thresholds() { @@ -36,107 +36,107 @@ function test_object_cache_default_thresholds() { function test_object_cache_comments_threshold() { add_filter( - 'site_status_persistent_object_cache_thresholds', + 'perflab_oc_site_status_persistent_object_cache_thresholds', function ( $thresholds ) { return array_merge( $thresholds, array( 'comments_count' => 0 ) ); } ); - $result = oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache( false ); $this->assertTrue( $result ); - remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); } function test_object_cache_posts_threshold() { add_filter( - 'site_status_persistent_object_cache_thresholds', + 'perflab_oc_site_status_persistent_object_cache_thresholds', function ( $thresholds ) { return array_merge( $thresholds, array( 'posts_count' => 0 ) ); } ); - $result = oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache( false ); $this->assertTrue( $result ); - remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); } function test_object_cache_terms_threshold() { add_filter( - 'site_status_persistent_object_cache_thresholds', + 'perflab_oc_site_status_persistent_object_cache_thresholds', function ( $thresholds ) { return array_merge( $thresholds, array( 'terms_count' => 1 ) ); } ); - $result = oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache( false ); $this->assertTrue( $result ); - remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); } function test_object_cache_options_threshold() { add_filter( - 'site_status_persistent_object_cache_thresholds', + 'perflab_oc_site_status_persistent_object_cache_thresholds', function ( $thresholds ) { return array_merge( $thresholds, array( 'options_count' => 100 ) ); } ); - $result = oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache( false ); $this->assertTrue( $result ); - remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); } function test_object_cache_users_threshold() { add_filter( - 'site_status_persistent_object_cache_thresholds', + 'perflab_oc_site_status_persistent_object_cache_thresholds', function ( $thresholds ) { return array_merge( $thresholds, array( 'users_count' => 0 ) ); } ); - $result = oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache( false ); $this->assertTrue( $result ); - remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); } function test_object_cache_alloptions_count_threshold() { add_filter( - 'site_status_persistent_object_cache_thresholds', + 'perflab_oc_site_status_persistent_object_cache_thresholds', function ( $thresholds ) { return array_merge( $thresholds, array( 'alloptions_count' => 100 ) ); } ); - $result = oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache( false ); $this->assertTrue( $result ); - remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); } function test_object_cache_alloptions_bytes_threshold() { add_filter( - 'site_status_persistent_object_cache_thresholds', + 'perflab_oc_site_status_persistent_object_cache_thresholds', function ( $thresholds ) { return array_merge( $thresholds, array( 'alloptions_bytes' => 1000 ) ); } ); - $result = oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache( false ); $this->assertTrue( $result ); - remove_all_filters( 'site_status_persistent_object_cache_thresholds' ); + remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); } } From db8994fbf1756a24b1de26e9d3a9ea3764493170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 17 Feb 2022 14:55:43 -0800 Subject: [PATCH 38/48] fix test --- .../persistent-object-cache-health-check/health-check-test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php index ccc3ea87c7..ea9b7c3de9 100644 --- a/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php +++ b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php @@ -29,7 +29,7 @@ function ( $thresholds ) use ( $bypassed ) { } function test_object_cache_default_thresholds() { - $result = oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache( false ); $this->assertFalse( $result ); } From a83ae10f10ea079795406556c7c5f2da111e76b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Sat, 26 Feb 2022 13:49:30 -0800 Subject: [PATCH 39/48] Update modules/object-cache/persistent-object-cache-health-check/load.php Co-authored-by: Felix Arntz --- .../object-cache/persistent-object-cache-health-check/load.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/object-cache/persistent-object-cache-health-check/load.php b/modules/object-cache/persistent-object-cache-health-check/load.php index 0813870c48..9192b36d3a 100644 --- a/modules/object-cache/persistent-object-cache-health-check/load.php +++ b/modules/object-cache/persistent-object-cache-health-check/load.php @@ -56,6 +56,7 @@ function perflab_oc_health_persistent_object_cache() { 'label' => __( 'Performance', 'performance-lab' ), 'color' => 'blue', ), + 'label' => __( 'A persistent object cache is being used', 'performance-lab' ), 'description' => sprintf( '

%s

', __( "WordPress performs at its best when a persistent object cache is used. A persistent object cache helps to reduce load on your SQL server significantly and allows WordPress to retrieve your site's content and settings much faster.", 'performance-lab' ) @@ -70,8 +71,6 @@ function perflab_oc_health_persistent_object_cache() { ); if ( wp_using_ext_object_cache() ) { - $result['label'] = __( 'A persistent object cache is being used', 'performance-lab' ); - return $result; } From fb4e749256eebdd73931fcf70cbc2a01bb279f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Sat, 26 Feb 2022 13:50:06 -0800 Subject: [PATCH 40/48] Update modules/object-cache/persistent-object-cache-health-check/load.php Co-authored-by: Felix Arntz --- .../persistent-object-cache-health-check/load.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/object-cache/persistent-object-cache-health-check/load.php b/modules/object-cache/persistent-object-cache-health-check/load.php index 9192b36d3a..da7ade0a45 100644 --- a/modules/object-cache/persistent-object-cache-health-check/load.php +++ b/modules/object-cache/persistent-object-cache-health-check/load.php @@ -94,9 +94,9 @@ function perflab_oc_health_persistent_object_cache() { $notes = __( 'Speak to your web host about what persistent object caches are available and how to enable them.', 'performance-lab' ); if ( ! empty( $available_services ) ) { - $notes .= sprintf( + $notes .= ' ' . sprintf( /* translators: Available object caching services. */ - __( ' Your host appears to support the following object caching services: %s.', 'performance-lab' ), + __( 'Your host appears to support the following object caching services: %s.', 'performance-lab' ), implode( ', ', $available_services ) ); } From fd07b49cc9e6b66ada30a3ce13e9cdd48611eb07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Sat, 26 Feb 2022 13:50:23 -0800 Subject: [PATCH 41/48] Update modules/object-cache/persistent-object-cache-health-check/load.php Co-authored-by: Felix Arntz --- .../persistent-object-cache-health-check/load.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/object-cache/persistent-object-cache-health-check/load.php b/modules/object-cache/persistent-object-cache-health-check/load.php index da7ade0a45..124d29a034 100644 --- a/modules/object-cache/persistent-object-cache-health-check/load.php +++ b/modules/object-cache/persistent-object-cache-health-check/load.php @@ -111,8 +111,8 @@ function perflab_oc_health_persistent_object_cache() { * * @since 1.0.0 * - * @param string $notes The notes appended to the health check description. - * @param array $available_services The list of available persistent object cache services. + * @param string $notes The notes appended to the health check description. + * @param array $available_services The list of available persistent object cache services. */ $notes = apply_filters( 'perflab_oc_site_status_persistent_object_cache_notes', $notes, $available_services ); From 873dc12d832ebb6ecd7a3237fc19662145cb0718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Mon, 28 Feb 2022 11:02:26 -0800 Subject: [PATCH 42/48] simplify filter logic --- .../load.php | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/modules/object-cache/persistent-object-cache-health-check/load.php b/modules/object-cache/persistent-object-cache-health-check/load.php index 124d29a034..b461827480 100644 --- a/modules/object-cache/persistent-object-cache-health-check/load.php +++ b/modules/object-cache/persistent-object-cache-health-check/load.php @@ -74,16 +74,7 @@ function perflab_oc_health_persistent_object_cache() { return $result; } - /** - * Filter whether to suggest using a persistent object cache. - * - * Plugin and theme authors should NOT use this filter to discourage the use of an object cache. - * - * @since 1.0.0 - * - * @param bool $suggest Whether to suggest using a persistent object cache. - */ - if ( ! apply_filters( 'perflab_oc_site_status_suggest_persistent_object_cache', false ) ) { + if ( ! perflab_oc_health_should_persistent_object_cache() ) { $result['label'] = __( 'A persistent object cache is not required', 'performance-lab' ); return $result; @@ -142,14 +133,21 @@ function perflab_oc_health_persistent_object_cache() { * * @since 1.0.0 * - * @param mixed $should_suggest Whether to suggest using a persistent object cache. + * @global wpdb $wpdb WordPress database abstraction object. + * * @return bool Whether to suggest using a persistent object cache. */ -function perflab_oc_health_should_persistent_object_cache( $should_suggest ) { +function perflab_oc_health_should_persistent_object_cache() { global $wpdb; - // Bypass expensive calls if `$should_suggest` was already set truthy. - if ( $should_suggest ) { + /** + * Filter to force suggestion to use a persistent object cache and bypass threshold checks. + * + * @since 1.0.0 + * + * @param bool $suggest Whether to suggest using a persistent object cache. + */ + if ( apply_filters( 'perflab_oc_site_status_suggest_persistent_object_cache', false ) ) { return true; } @@ -216,7 +214,6 @@ function perflab_oc_health_should_persistent_object_cache( $should_suggest ) { return false; } -add_filter( 'perflab_oc_site_status_suggest_persistent_object_cache', 'perflab_oc_health_should_persistent_object_cache', 20 ); /** * Returns a list of available persistent object cache services. From 1ea68fd89557f09235dadb7ecb3a8e1bfd864bce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Mon, 28 Feb 2022 11:17:30 -0800 Subject: [PATCH 43/48] update tests --- .../health-check-test.php | 38 +++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php index ea9b7c3de9..15ac37f557 100644 --- a/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php +++ b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php @@ -8,32 +8,22 @@ class Object_Cache_Health_Check_Tests extends WP_UnitTestCase { - function test_object_cache_thresholds_check_is_bypassed() { - $bypassed = true; + function test_object_cache_default_thresholds() { + $result = perflab_oc_health_should_persistent_object_cache(); - add_filter( - 'perflab_oc_site_status_persistent_object_cache_thresholds', - function ( $thresholds ) use ( $bypassed ) { - $bypassed = false; + $this->assertFalse( $result ); + } - return $thresholds; - } - ); + function test_object_cache_thresholds_check_can_be_bypassed() { + add_filter('perflab_oc_site_status_persistent_object_cache_thresholds', '__return_true'); - $result = perflab_oc_health_should_persistent_object_cache( true ); + $result = perflab_oc_health_should_persistent_object_cache(); $this->assertTrue( $result ); - $this->assertTrue( $bypassed ); remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); } - function test_object_cache_default_thresholds() { - $result = perflab_oc_health_should_persistent_object_cache( false ); - - $this->assertFalse( $result ); - } - function test_object_cache_comments_threshold() { add_filter( 'perflab_oc_site_status_persistent_object_cache_thresholds', @@ -42,7 +32,7 @@ function ( $thresholds ) { } ); - $result = perflab_oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache(); $this->assertTrue( $result ); @@ -57,7 +47,7 @@ function ( $thresholds ) { } ); - $result = perflab_oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache(); $this->assertTrue( $result ); @@ -72,7 +62,7 @@ function ( $thresholds ) { } ); - $result = perflab_oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache(); $this->assertTrue( $result ); @@ -87,7 +77,7 @@ function ( $thresholds ) { } ); - $result = perflab_oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache(); $this->assertTrue( $result ); @@ -102,7 +92,7 @@ function ( $thresholds ) { } ); - $result = perflab_oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache(); $this->assertTrue( $result ); @@ -117,7 +107,7 @@ function ( $thresholds ) { } ); - $result = perflab_oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache(); $this->assertTrue( $result ); @@ -132,7 +122,7 @@ function ( $thresholds ) { } ); - $result = perflab_oc_health_should_persistent_object_cache( false ); + $result = perflab_oc_health_should_persistent_object_cache(); $this->assertTrue( $result ); From ea064619a973649533d57470a8dad48c31aff8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Mon, 28 Feb 2022 11:19:28 -0800 Subject: [PATCH 44/48] spacing --- .../persistent-object-cache-health-check/health-check-test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php index 15ac37f557..b9a1e82f4b 100644 --- a/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php +++ b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php @@ -15,7 +15,7 @@ function test_object_cache_default_thresholds() { } function test_object_cache_thresholds_check_can_be_bypassed() { - add_filter('perflab_oc_site_status_persistent_object_cache_thresholds', '__return_true'); + add_filter( 'perflab_oc_site_status_persistent_object_cache_thresholds', '__return_true' ); $result = perflab_oc_health_should_persistent_object_cache(); From badede0a6af222780099fdbee317c23ee313a6fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Mon, 28 Feb 2022 12:13:56 -0800 Subject: [PATCH 45/48] Update modules/object-cache/persistent-object-cache-health-check/load.php Co-authored-by: Felix Arntz --- .../object-cache/persistent-object-cache-health-check/load.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/object-cache/persistent-object-cache-health-check/load.php b/modules/object-cache/persistent-object-cache-health-check/load.php index b461827480..221037b2f8 100644 --- a/modules/object-cache/persistent-object-cache-health-check/load.php +++ b/modules/object-cache/persistent-object-cache-health-check/load.php @@ -127,8 +127,6 @@ function perflab_oc_health_persistent_object_cache() { } /** - * Callback for `site_status_persistent_object_cache` filter. - * * Determines whether to suggest using a persistent object cache. * * @since 1.0.0 From 6291513ddd924a871b656d7e063b3cac92ed72bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Mon, 28 Feb 2022 12:21:36 -0800 Subject: [PATCH 46/48] simplify tests --- .../health-check-test.php | 113 +++--------------- 1 file changed, 17 insertions(+), 96 deletions(-) diff --git a/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php index b9a1e82f4b..ea87bb195b 100644 --- a/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php +++ b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php @@ -15,118 +15,39 @@ function test_object_cache_default_thresholds() { } function test_object_cache_thresholds_check_can_be_bypassed() { - add_filter( 'perflab_oc_site_status_persistent_object_cache_thresholds', '__return_true' ); + add_filter( 'perflab_oc_site_status_suggest_persistent_object_cache', '__return_true' ); $result = perflab_oc_health_should_persistent_object_cache(); $this->assertTrue( $result ); - - remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); - } - - function test_object_cache_comments_threshold() { - add_filter( - 'perflab_oc_site_status_persistent_object_cache_thresholds', - function ( $thresholds ) { - return array_merge( $thresholds, array( 'comments_count' => 0 ) ); - } - ); - - $result = perflab_oc_health_should_persistent_object_cache(); - - $this->assertTrue( $result ); - - remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); - } - - function test_object_cache_posts_threshold() { - add_filter( - 'perflab_oc_site_status_persistent_object_cache_thresholds', - function ( $thresholds ) { - return array_merge( $thresholds, array( 'posts_count' => 0 ) ); - } - ); - - $result = perflab_oc_health_should_persistent_object_cache(); - - $this->assertTrue( $result ); - - remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); - } - - function test_object_cache_terms_threshold() { - add_filter( - 'perflab_oc_site_status_persistent_object_cache_thresholds', - function ( $thresholds ) { - return array_merge( $thresholds, array( 'terms_count' => 1 ) ); - } - ); - - $result = perflab_oc_health_should_persistent_object_cache(); - - $this->assertTrue( $result ); - - remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); } - function test_object_cache_options_threshold() { + /** + * + * @dataProvider thresholds + */ + function test_object_cache_thresholds( $threshold, $count ) { add_filter( 'perflab_oc_site_status_persistent_object_cache_thresholds', - function ( $thresholds ) { - return array_merge( $thresholds, array( 'options_count' => 100 ) ); + function ( $thresholds ) use ( $threshold, $count ) { + return array_merge( $thresholds, array( $threshold => $count ) ); } ); $result = perflab_oc_health_should_persistent_object_cache(); $this->assertTrue( $result ); - - remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); } - function test_object_cache_users_threshold() { - add_filter( - 'perflab_oc_site_status_persistent_object_cache_thresholds', - function ( $thresholds ) { - return array_merge( $thresholds, array( 'users_count' => 0 ) ); - } + function thresholds() { + return array( + array( 'comments_count', 0 ), + array( 'posts_count', 0 ), + array( 'terms_count', 1 ), + array( 'options_count', 100 ), + array( 'users_count', 0 ), + array( 'alloptions_count', 100 ), + array( 'alloptions_bytes', 1000 ), ); - - $result = perflab_oc_health_should_persistent_object_cache(); - - $this->assertTrue( $result ); - - remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); } - - function test_object_cache_alloptions_count_threshold() { - add_filter( - 'perflab_oc_site_status_persistent_object_cache_thresholds', - function ( $thresholds ) { - return array_merge( $thresholds, array( 'alloptions_count' => 100 ) ); - } - ); - - $result = perflab_oc_health_should_persistent_object_cache(); - - $this->assertTrue( $result ); - - remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); - } - - function test_object_cache_alloptions_bytes_threshold() { - add_filter( - 'perflab_oc_site_status_persistent_object_cache_thresholds', - function ( $thresholds ) { - return array_merge( $thresholds, array( 'alloptions_bytes' => 1000 ) ); - } - ); - - $result = perflab_oc_health_should_persistent_object_cache(); - - $this->assertTrue( $result ); - - remove_all_filters( 'perflab_oc_site_status_persistent_object_cache_thresholds' ); - } - } From 0390c3a2645f5bd8de263f8d99823c6c2b062009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Mon, 28 Feb 2022 12:25:10 -0800 Subject: [PATCH 47/48] formatting --- .../persistent-object-cache-health-check/health-check-test.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php index ea87bb195b..9aa9eb385e 100644 --- a/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php +++ b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php @@ -23,7 +23,6 @@ function test_object_cache_thresholds_check_can_be_bypassed() { } /** - * * @dataProvider thresholds */ function test_object_cache_thresholds( $threshold, $count ) { From bbf79d8058973d7d7afd2caa7b461c300aa6762b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Mon, 28 Feb 2022 12:26:28 -0800 Subject: [PATCH 48/48] remove useless vars from tests --- .../health-check-test.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php index 9aa9eb385e..013ce42282 100644 --- a/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php +++ b/tests/modules/object-cache/persistent-object-cache-health-check/health-check-test.php @@ -9,17 +9,17 @@ class Object_Cache_Health_Check_Tests extends WP_UnitTestCase { function test_object_cache_default_thresholds() { - $result = perflab_oc_health_should_persistent_object_cache(); - - $this->assertFalse( $result ); + $this->assertFalse( + perflab_oc_health_should_persistent_object_cache() + ); } function test_object_cache_thresholds_check_can_be_bypassed() { add_filter( 'perflab_oc_site_status_suggest_persistent_object_cache', '__return_true' ); - $result = perflab_oc_health_should_persistent_object_cache(); - - $this->assertTrue( $result ); + $this->assertTrue( + perflab_oc_health_should_persistent_object_cache() + ); } /** @@ -33,9 +33,9 @@ function ( $thresholds ) use ( $threshold, $count ) { } ); - $result = perflab_oc_health_should_persistent_object_cache(); - - $this->assertTrue( $result ); + $this->assertTrue( + perflab_oc_health_should_persistent_object_cache() + ); } function thresholds() {