Skip to content

Implement opt-in PERFLAB_PLACE_OBJECT_CACHE_DROPIN for Server-Timing object-cache.php placement #1996

New issue

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

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

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions plugins/performance-lab/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,13 @@
* the frontend.
*
* This function will short-circuit if at least one of the constants
* 'PERFLAB_DISABLE_SERVER_TIMING' or 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' is
* set as true.
* 'PERFLAB_DISABLE_SERVER_TIMING' or
* 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' is set as true or if the
* 'PERFLAB_PLACE_OBJECT_CACHE_DROPIN' constant is not set to a truthy value.
*
* @since 1.8.0
* @since 2.1.0 No longer attempts to use two of the drop-ins together.
* @since n.e.x.t No longer places the drop-in on new sites by default, unless the `PERFLAB_PLACE_OBJECT_CACHE_DROPIN` constant is set to true.
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*/
Expand All @@ -161,7 +163,14 @@
return;
}

// Bail if the drop-in is not enabled.
if ( ! defined( 'PERFLAB_PLACE_OBJECT_CACHE_DROPIN' ) || ! PERFLAB_PLACE_OBJECT_CACHE_DROPIN ) {
return;

Check warning on line 168 in plugins/performance-lab/load.php

View check run for this annotation

Codecov / codecov/patch

plugins/performance-lab/load.php#L168

Added line #L168 was not covered by tests
}

// Bail if disabled via constant.
// This constant is maintained only for backward compatibility and should not be relied upon in new implementations.
// Use the 'PERFLAB_PLACE_OBJECT_CACHE_DROPIN' constant instead to control drop-in placement.
if ( defined( 'PERFLAB_DISABLE_OBJECT_CACHE_DROPIN' ) && PERFLAB_DISABLE_OBJECT_CACHE_DROPIN ) {
return;
}
Expand Down
15 changes: 15 additions & 0 deletions plugins/performance-lab/tests/test-load.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@

class Test_Load extends WP_UnitTestCase {

/**
* Runs the routine before each test is executed.
*/
public function set_up(): void {
parent::set_up();

/*
* This constant is not set by default in production.
* However, it is needed for all tests that cover placement of the object cache drop-in.
*/
if ( ! defined( 'PERFLAB_PLACE_OBJECT_CACHE_DROPIN' ) ) {
define( 'PERFLAB_PLACE_OBJECT_CACHE_DROPIN', true );
}
}

public function test_perflab_get_generator_content(): void {
$expected = 'performance-lab ' . PERFLAB_VERSION . '; plugins: ';
$content = perflab_get_generator_content();
Expand Down