From d588f23282eeb40c5f198232d7ad4aafcaab7107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Tue, 24 Jan 2023 10:33:27 -0800 Subject: [PATCH 1/7] Update load.php --- load.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/load.php b/load.php index 9b9cffd474..1bb2c6dbf9 100644 --- a/load.php +++ b/load.php @@ -290,6 +290,17 @@ function perflab_maybe_set_object_cache_dropin() { if ( PERFLAB_OBJECT_CACHE_DROPIN_VERSION ) { return; } + + /** + * Filters whether the Perflab server timing drop-in should be set. + * + * @since x.x.x + * + * @param bool Whether the server timing drop-in should be set. + */ + if ( apply_filters( 'perflab_object_cache_dropin', '__return_false' ) ) { + return; + } // Bail if already attempted before timeout has been completed. // This is present in case placing the file fails for some reason, to avoid From 6001808bccbb8915c2b2209e32ba29571f55af24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Tue, 24 Jan 2023 11:41:53 -0800 Subject: [PATCH 2/7] remove whitespace --- load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/load.php b/load.php index 1bb2c6dbf9..f16d15ccdc 100644 --- a/load.php +++ b/load.php @@ -290,7 +290,7 @@ function perflab_maybe_set_object_cache_dropin() { if ( PERFLAB_OBJECT_CACHE_DROPIN_VERSION ) { return; } - + /** * Filters whether the Perflab server timing drop-in should be set. * From ef841af418ab60c2660d5b6952215587660ff084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Fri, 27 Jan 2023 10:03:59 -0800 Subject: [PATCH 3/7] tweaks Co-authored-by: Felix Arntz --- load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/load.php b/load.php index f16d15ccdc..ce09df3553 100644 --- a/load.php +++ b/load.php @@ -298,7 +298,7 @@ function perflab_maybe_set_object_cache_dropin() { * * @param bool Whether the server timing drop-in should be set. */ - if ( apply_filters( 'perflab_object_cache_dropin', '__return_false' ) ) { + if ( apply_filters( 'perflab_disable_object_cache_dropin', false ) ) { return; } From 78d83c1288b29dbf2f78cefe6dde38b28ad1eae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Fri, 27 Jan 2023 10:04:13 -0800 Subject: [PATCH 4/7] fix @since tag Co-authored-by: Felix Arntz --- load.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/load.php b/load.php index ce09df3553..f739c084c8 100644 --- a/load.php +++ b/load.php @@ -294,7 +294,7 @@ function perflab_maybe_set_object_cache_dropin() { /** * Filters whether the Perflab server timing drop-in should be set. * - * @since x.x.x + * @since n.e.x.t * * @param bool Whether the server timing drop-in should be set. */ From 5c736914eed70dcc1111d3355eb1ed52e0207eaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Fri, 27 Jan 2023 10:26:11 -0800 Subject: [PATCH 5/7] add test case --- tests/server-timing/load-tests.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/server-timing/load-tests.php b/tests/server-timing/load-tests.php index 3dfec9b29e..454bc8604f 100644 --- a/tests/server-timing/load-tests.php +++ b/tests/server-timing/load-tests.php @@ -40,6 +40,23 @@ public function test_perflab_server_timing_use_output_buffer() { add_filter( 'perflab_server_timing_use_output_buffer', '__return_true' ); $this->assertTrue( perflab_server_timing_use_output_buffer() ); } + + public function test_perflab_object_cache_dropin_may_be_disabled_via_filter() { + global $wp_filesystem; + + $this->set_up_mock_filesystem(); + + // Ensure PL object-cache.php drop-in is not present and constant is not set. + $this->assertFalse( $wp_filesystem->exists( WP_CONTENT_DIR . '/object-cache.php' ) ); + $this->assertFalse( PERFLAB_OBJECT_CACHE_DROPIN_VERSION ); + + // Add filter to disable drop-in. + add_filter( 'perflab_disable_object_cache_dropin', '__return_true' ); + + // Run function to place drop-in and ensure it still doesn't exist afterwards. + perflab_maybe_set_object_cache_dropin(); + $this->assertFalse( $wp_filesystem->exists( WP_CONTENT_DIR . '/object-cache.php' ) ); + } public function test_perflab_wrap_server_timing() { $cb = function() { From adcda0170b84895468ec4ca5018976a65e8b664c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Fri, 27 Jan 2023 10:28:05 -0800 Subject: [PATCH 6/7] remove whitespace --- tests/server-timing/load-tests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/server-timing/load-tests.php b/tests/server-timing/load-tests.php index 454bc8604f..8fcff120ff 100644 --- a/tests/server-timing/load-tests.php +++ b/tests/server-timing/load-tests.php @@ -40,7 +40,7 @@ public function test_perflab_server_timing_use_output_buffer() { add_filter( 'perflab_server_timing_use_output_buffer', '__return_true' ); $this->assertTrue( perflab_server_timing_use_output_buffer() ); } - + public function test_perflab_object_cache_dropin_may_be_disabled_via_filter() { global $wp_filesystem; From 198dd3a6184297eca3bcaf919303cbfe5bfc9499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Fri, 27 Jan 2023 10:35:03 -0800 Subject: [PATCH 7/7] move test to correct file --- tests/load-tests.php | 17 +++++++++++++++++ tests/server-timing/load-tests.php | 17 ----------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/load-tests.php b/tests/load-tests.php index be977801e5..f45ee7e8f5 100644 --- a/tests/load-tests.php +++ b/tests/load-tests.php @@ -343,6 +343,23 @@ public function test_perflab_maybe_set_object_cache_dropin_with_conflict_and_ori $this->assertSame( $dummy_file_content2, $wp_filesystem->get_contents( WP_CONTENT_DIR . '/object-cache-plst-orig.php' ) ); } + public function test_perflab_object_cache_dropin_may_be_disabled_via_filter() { + global $wp_filesystem; + + $this->set_up_mock_filesystem(); + + // Ensure PL object-cache.php drop-in is not present and constant is not set. + $this->assertFalse( $wp_filesystem->exists( WP_CONTENT_DIR . '/object-cache.php' ) ); + $this->assertFalse( PERFLAB_OBJECT_CACHE_DROPIN_VERSION ); + + // Add filter to disable drop-in. + add_filter( 'perflab_disable_object_cache_dropin', '__return_true' ); + + // Run function to place drop-in and ensure it still doesn't exist afterwards. + perflab_maybe_set_object_cache_dropin(); + $this->assertFalse( $wp_filesystem->exists( WP_CONTENT_DIR . '/object-cache.php' ) ); + } + private function set_up_mock_filesystem() { global $wp_filesystem; diff --git a/tests/server-timing/load-tests.php b/tests/server-timing/load-tests.php index 8fcff120ff..3dfec9b29e 100644 --- a/tests/server-timing/load-tests.php +++ b/tests/server-timing/load-tests.php @@ -41,23 +41,6 @@ public function test_perflab_server_timing_use_output_buffer() { $this->assertTrue( perflab_server_timing_use_output_buffer() ); } - public function test_perflab_object_cache_dropin_may_be_disabled_via_filter() { - global $wp_filesystem; - - $this->set_up_mock_filesystem(); - - // Ensure PL object-cache.php drop-in is not present and constant is not set. - $this->assertFalse( $wp_filesystem->exists( WP_CONTENT_DIR . '/object-cache.php' ) ); - $this->assertFalse( PERFLAB_OBJECT_CACHE_DROPIN_VERSION ); - - // Add filter to disable drop-in. - add_filter( 'perflab_disable_object_cache_dropin', '__return_true' ); - - // Run function to place drop-in and ensure it still doesn't exist afterwards. - perflab_maybe_set_object_cache_dropin(); - $this->assertFalse( $wp_filesystem->exists( WP_CONTENT_DIR . '/object-cache.php' ) ); - } - public function test_perflab_wrap_server_timing() { $cb = function() { return 123;