From 825a85e2f66060e56e917f0268b4ac1e651aa210 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Wed, 3 Apr 2024 10:29:40 +0530 Subject: [PATCH 1/7] Move typos config to .github --- _typos.toml => .github/typos.toml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename _typos.toml => .github/typos.toml (100%) diff --git a/_typos.toml b/.github/typos.toml similarity index 100% rename from _typos.toml rename to .github/typos.toml From da1c6917b34498c38408e2887ea5f067b7e53ff4 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Wed, 3 Apr 2024 10:30:49 +0530 Subject: [PATCH 2/7] Update spell-check workflow to use typos config from .github --- .github/workflows/spell-check.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 7fe8b06719..730d0f0df0 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -10,3 +10,5 @@ jobs: - uses: actions/checkout@v3 - name: Search for misspellings uses: crate-ci/typos@master + with: + config: ./.github/typos.toml From f5bb87d973eb83421be2268511ec755333558ef4 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 3 Apr 2024 18:21:03 -0700 Subject: [PATCH 3/7] Fix PHPUnit test failures in trunk due to large option autoload optimization in core. --- .../audit-autoloaded-options-test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php index f649446339..f9a64803d3 100644 --- a/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php +++ b/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php @@ -148,7 +148,9 @@ static function () { */ public static function set_autoloaded_option( $bytes = 800000 ) { $heavy_option_string = wp_generate_password( $bytes ); - add_option( self::AUTOLOADED_OPTION_KEY, $heavy_option_string ); + + // Force autoloading so that WordPress core does not override it. See https://core.trac.wordpress.org/changeset/57920. + add_option( self::AUTOLOADED_OPTION_KEY, $heavy_option_string, '', true ); } /** From ac329f6a73480926ddd7cc2127d63d40608ead5c Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 3 Apr 2024 18:37:33 -0700 Subject: [PATCH 4/7] Fix queries to take additional autoload values into account. --- .../audit-autoloaded-options/helper.php | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/includes/site-health/audit-autoloaded-options/helper.php b/includes/site-health/audit-autoloaded-options/helper.php index 2436dfd90b..6038d12284 100644 --- a/includes/site-health/audit-autoloaded-options/helper.php +++ b/includes/site-health/audit-autoloaded-options/helper.php @@ -101,7 +101,22 @@ function perflab_aao_autoloaded_options_test() { */ function perflab_aao_autoloaded_options_size() { global $wpdb; - return (int) $wpdb->get_var( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'' ); + + if ( function_exists( 'wp_autoload_values_to_autoload' ) ) { + $autoload_values = wp_autoload_values_to_autoload(); + } else { + $autoload_values = array( 'yes' ); + } + + return (int) $wpdb->get_var( + $wpdb->prepare( + sprintf( + 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload IN (%s)', + implode( ',', array_fill( 0, count( $autoload_values ), '%s' ) ) + ), + $autoload_values + ) + ); } /** @@ -130,7 +145,21 @@ function perflab_aao_query_autoloaded_options() { */ $option_threshold = apply_filters( 'perflab_aao_autoloaded_options_table_threshold', 100 ); - return $wpdb->get_results( $wpdb->prepare( "SELECT option_name, LENGTH(option_value) AS option_value_length FROM {$wpdb->options} WHERE autoload='yes' AND LENGTH(option_value) > %d ORDER BY option_value_length DESC LIMIT 20", $option_threshold ) ); + if ( function_exists( 'wp_autoload_values_to_autoload' ) ) { + $autoload_values = wp_autoload_values_to_autoload(); + } else { + $autoload_values = array( 'yes' ); + } + + return $wpdb->get_results( + $wpdb->prepare( + sprintf( + "SELECT option_name, LENGTH(option_value) AS option_value_length FROM {$wpdb->options} WHERE autoload IN (%s)", + implode( ',', array_fill( 0, count( $autoload_values ), '%s' ) ) + ) . ' AND LENGTH(option_value) > %d ORDER BY option_value_length DESC LIMIT 20', + array_merge( $autoload_values, array( $option_threshold ) ) + ) + ); } /** From f3969a87f2333d1353fbecb7fd644b1fd04f0ae2 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 3 Apr 2024 18:43:08 -0700 Subject: [PATCH 5/7] Fix another autoload query in tests. --- .../audit-autoloaded-options-test.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php index f9a64803d3..34e00a5bf0 100644 --- a/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php +++ b/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php @@ -59,7 +59,22 @@ public function test_perflab_aao_autoloaded_options_test_warning() { */ public function test_perflab_aao_autoloaded_options_size() { global $wpdb; - $autoloaded_options_size = $wpdb->get_var( 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload = \'yes\'' ); + + if ( function_exists( 'wp_autoload_values_to_autoload' ) ) { + $autoload_values = wp_autoload_values_to_autoload(); + } else { + $autoload_values = array( 'yes' ); + } + + $autoloaded_options_size = $wpdb->get_var( + $wpdb->prepare( + sprintf( + 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload IN (%s)', + implode( ',', array_fill( 0, count( $autoload_values ), '%s' ) ) + ), + $autoload_values + ) + ); $this->assertEquals( $autoloaded_options_size, perflab_aao_autoloaded_options_size() ); // Add autoload option. From cb548fd829880b924377ceeaffcbd52f4c0a787b Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 4 Apr 2024 07:38:20 -0700 Subject: [PATCH 6/7] Avoid unnecessary concatenation in queries. Co-authored-by: Mukesh Panchal --- includes/site-health/audit-autoloaded-options/helper.php | 2 +- .../audit-autoloaded-options/audit-autoloaded-options-test.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/site-health/audit-autoloaded-options/helper.php b/includes/site-health/audit-autoloaded-options/helper.php index 6038d12284..fcba4568c4 100644 --- a/includes/site-health/audit-autoloaded-options/helper.php +++ b/includes/site-health/audit-autoloaded-options/helper.php @@ -111,7 +111,7 @@ function perflab_aao_autoloaded_options_size() { return (int) $wpdb->get_var( $wpdb->prepare( sprintf( - 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload IN (%s)', + "SELECT SUM(LENGTH(option_value)) FROM $wpdb->options WHERE autoload IN (%s)", implode( ',', array_fill( 0, count( $autoload_values ), '%s' ) ) ), $autoload_values diff --git a/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php index 34e00a5bf0..7e8ccdf593 100644 --- a/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php +++ b/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php @@ -69,7 +69,7 @@ public function test_perflab_aao_autoloaded_options_size() { $autoloaded_options_size = $wpdb->get_var( $wpdb->prepare( sprintf( - 'SELECT SUM(LENGTH(option_value)) FROM ' . $wpdb->prefix . 'options WHERE autoload IN (%s)', + "SELECT SUM(LENGTH(option_value)) FROM $wpdb->options WHERE autoload IN (%s)", implode( ',', array_fill( 0, count( $autoload_values ), '%s' ) ) ), $autoload_values From 031658609d93296d6eb556f086a78eba92d879e2 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 4 Apr 2024 08:53:36 -0700 Subject: [PATCH 7/7] Implement helper function to get autoload values to autoload. --- .../audit-autoloaded-options/helper.php | 27 ++++++++++++------- .../audit-autoloaded-options-test.php | 6 +---- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/includes/site-health/audit-autoloaded-options/helper.php b/includes/site-health/audit-autoloaded-options/helper.php index fcba4568c4..54f92961a8 100644 --- a/includes/site-health/audit-autoloaded-options/helper.php +++ b/includes/site-health/audit-autoloaded-options/helper.php @@ -102,11 +102,7 @@ function perflab_aao_autoloaded_options_test() { function perflab_aao_autoloaded_options_size() { global $wpdb; - if ( function_exists( 'wp_autoload_values_to_autoload' ) ) { - $autoload_values = wp_autoload_values_to_autoload(); - } else { - $autoload_values = array( 'yes' ); - } + $autoload_values = perflab_aao_get_autoload_values_to_autoload(); return (int) $wpdb->get_var( $wpdb->prepare( @@ -145,11 +141,7 @@ function perflab_aao_query_autoloaded_options() { */ $option_threshold = apply_filters( 'perflab_aao_autoloaded_options_table_threshold', 100 ); - if ( function_exists( 'wp_autoload_values_to_autoload' ) ) { - $autoload_values = wp_autoload_values_to_autoload(); - } else { - $autoload_values = array( 'yes' ); - } + $autoload_values = perflab_aao_get_autoload_values_to_autoload(); return $wpdb->get_results( $wpdb->prepare( @@ -256,3 +248,18 @@ function perflab_aao_get_disabled_autoloaded_options_table() { return $html_table; } + +/** + * Gets the autoload values in the database that should trigger their option to be autoloaded. + * + * @since n.e.x.t + * + * @return array List of autoload values. + */ +function perflab_aao_get_autoload_values_to_autoload() { + if ( function_exists( 'wp_autoload_values_to_autoload' ) ) { + return wp_autoload_values_to_autoload(); + } + + return array( 'yes' ); +} diff --git a/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php index 7e8ccdf593..afcb60be02 100644 --- a/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php +++ b/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php @@ -60,11 +60,7 @@ public function test_perflab_aao_autoloaded_options_test_warning() { public function test_perflab_aao_autoloaded_options_size() { global $wpdb; - if ( function_exists( 'wp_autoload_values_to_autoload' ) ) { - $autoload_values = wp_autoload_values_to_autoload(); - } else { - $autoload_values = array( 'yes' ); - } + $autoload_values = perflab_aao_get_autoload_values_to_autoload(); $autoloaded_options_size = $wpdb->get_var( $wpdb->prepare(