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

Draft
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Draft
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
10 changes: 8 additions & 2 deletions plugins/performance-lab/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@
* 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.
Expand All @@ -156,6 +157,11 @@
function perflab_maybe_set_object_cache_dropin(): void {
global $wp_filesystem;

// 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 162 in plugins/performance-lab/load.php

View check run for this annotation

Codecov / codecov/patch

plugins/performance-lab/load.php#L162

Added line #L162 was not covered by tests
}

// Bail if Server-Timing is disabled entirely.
if ( defined( 'PERFLAB_DISABLE_SERVER_TIMING' ) && PERFLAB_DISABLE_SERVER_TIMING ) {
return;
Expand Down
11 changes: 11 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,17 @@

class Test_Load extends WP_UnitTestCase {

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

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