Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Update server-timing object-cache path and exclude pattern in phpcs.x…
…ml.dist
  • Loading branch information
thelovekesh committed Mar 13, 2024
commit 29dfb4c2d040521af503010eb01c4ea7753599cd
12 changes: 6 additions & 6 deletions includes/server-timing/object-cache.copy.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ function perflab_load_server_timing_api_from_dropin() {

$plugins_dir = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins';
$plugin_dir = $plugins_dir . '/performance-lab/';
if ( ! file_exists( $plugin_dir . 'server-timing/load.php' ) ) {
if ( ! file_exists( $plugin_dir . 'includes/server-timing/load.php' ) ) {
$plugin_dir = $plugins_dir . '/performance/';
if ( ! file_exists( $plugin_dir . 'server-timing/load.php' ) ) {
if ( ! file_exists( $plugin_dir . 'includes/server-timing/load.php' ) ) {
return;
}
}

require_once $plugin_dir . 'server-timing/class-perflab-server-timing-metric.php';
require_once $plugin_dir . 'server-timing/class-perflab-server-timing.php';
require_once $plugin_dir . 'server-timing/load.php';
require_once $plugin_dir . 'server-timing/defaults.php';
require_once $plugin_dir . 'includes/server-timing/class-perflab-server-timing-metric.php';
require_once $plugin_dir . 'includes/server-timing/class-perflab-server-timing.php';
require_once $plugin_dir . 'includes/server-timing/load.php';
require_once $plugin_dir . 'includes/server-timing/defaults.php';
Comment on lines -61 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thelovekesh Now that I see this change, moving the files for the Server-Timing API is tricky from a backward compatibility perspective. Here's why:

  • The wp-content/object-cache.php drop-in may already be placed on some sites, from an older Performance Lab version. As such, it would try to load the old paths, which wouldn't work. It wouldn't cause a fatal error because of the checks above, but it just wouldn't load the API.
  • In order to fix that, we'll have to enhance the logic that places that drop-in file (i.e. copies from object-cache.copy.php to the actual drop-in) so that it detects whether the current file is outdated.
  • I'm happy to open another PR for that. However, at a minimum, let's update the drop-in version number in this PR from 2 to 3 (in both the file header and constant).

Copy link
Member

@felixarntz felixarntz Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thelovekesh I've opened #1047 for the purpose of updating an older version of the drop-in, please take a look. Depending which of the two PRs gets merged first, the other one will require a minor update (to sync the version numbers and file paths).

}
}
perflab_load_server_timing_api_from_dropin();
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</rule>

<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
<exclude-pattern>server-timing/object-cache.copy.php</exclude-pattern>
<exclude-pattern>includes/server-timing/object-cache.copy.php</exclude-pattern>
</rule>

<file>.</file>
Expand Down
2 changes: 1 addition & 1 deletion tests/load-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function test_perflab_maybe_set_object_cache_dropin_no_conflict() {
// Run function to place drop-in and ensure it exists afterwards.
perflab_maybe_set_object_cache_dropin();
$this->assertTrue( $wp_filesystem->exists( WP_CONTENT_DIR . '/object-cache.php' ) );
$this->assertSame( file_get_contents( PERFLAB_PLUGIN_DIR_PATH . 'server-timing/object-cache.copy.php' ), $wp_filesystem->get_contents( WP_CONTENT_DIR . '/object-cache.php' ) );
$this->assertSame( file_get_contents( PERFLAB_PLUGIN_DIR_PATH . 'includes/server-timing/object-cache.copy.php' ), $wp_filesystem->get_contents( WP_CONTENT_DIR . '/object-cache.php' ) );
}

public function test_perflab_maybe_set_object_cache_dropin_no_conflict_but_failing() {
Expand Down