Skip to content

Commit

Permalink
Jetpack Boost: Refactor page cache setup and improve error handling (…
Browse files Browse the repository at this point in the history
…#35854)

* At least return which error was unknown

* Ensure that Boost Cache filename is found

* Move setup to `page_cache`

* Define the plugin filename constant

* Resolve plugin_dir_name based on the plugin name

* Mono fix

* Add plugins/boost changelog entry.

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/8001883684
  • Loading branch information
pyronaur authored and matticbot committed Feb 22, 2024
1 parent a9c073b commit 136ed52
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This is an alpha version! The changes listed here are not final.
- Critical CSS: Prevent missing archive pages from breaking generation process
- Fix pricing bug.
- Image Size Analysis: Update summary groups to align with status icons.
- Jetpack Boost: Enhanced error handling for page cache setup and refactored related code for clarity.
- Jetpack Boost: Improved error handling
- JS and CSS concat: Fix minification

Expand Down
2 changes: 1 addition & 1 deletion app/assets/dist/jetpack-boost.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-components', 'wp-compose', 'wp-date', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives'), 'version' => 'ae64d0cd229b503318e2');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-components', 'wp-compose', 'wp-date', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives'), 'version' => 'd72373e23819e557f1f9');
6 changes: 3 additions & 3 deletions app/assets/dist/jetpack-boost.js

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions app/modules/cache/Page_Cache_Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static function verify_permalink_setting() {
*
* Returns true if the files were setup correctly, or WP_Error if there was a problem.
*
* @return bool|WP_Error
* @return bool|\WP_Error
*/
private static function create_advanced_cache() {
$advanced_cache_filename = WP_CONTENT_DIR . '/advanced-cache.php';
Expand All @@ -82,8 +82,12 @@ private static function create_advanced_cache() {
}
}

$boost_cache_filename = WP_CONTENT_DIR . '/plugins/' . basename( dirname( plugin_dir_path( __FILE__ ), 3 ) ) . '/app/modules/cache/pre-wordpress/Boost_Cache.php';
$contents = '<?php
$plugin_dir_name = untrailingslashit( str_replace( JETPACK_BOOST_PLUGIN_FILENAME, '', JETPACK_BOOST_PLUGIN_BASE ) );
$boost_cache_filename = WP_CONTENT_DIR . '/plugins/' . $plugin_dir_name . '/app/modules/cache/pre-wordpress/Boost_Cache.php';
if ( ! file_exists( $boost_cache_filename ) ) {
return new \WP_Error( 'boost-cache-file-not-found', 'Boost_Cache.php not found' );
}
$contents = '<?php
// ' . Page_Cache::ADVANCED_CACHE_SIGNATURE . ' - ' . Page_Cache::ADVANCED_CACHE_VERSION . '
if ( ! file_exists( \'' . $boost_cache_filename . '\' ) ) {
return;
Expand Down
4 changes: 4 additions & 0 deletions jetpack-boost.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
define( 'JETPACK_BOOST_PLUGIN_BASE', plugin_basename( __FILE__ ) );
}

if ( ! defined( 'JETPACK_BOOST_PLUGIN_FILENAME' ) ) {
define( 'JETPACK_BOOST_PLUGIN_FILENAME', basename( __FILE__ ) );
}

if ( ! defined( 'JETPACK_BOOST_REST_NAMESPACE' ) ) {
define( 'JETPACK_BOOST_REST_NAMESPACE', 'jetpack-boost/v1' );
}
Expand Down
4 changes: 2 additions & 2 deletions wp-js-data-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,10 @@ function jetpack_boost_initialize_datasync() {
jetpack_boost_register_option(
'page_cache_error',
Schema::as_string()
->nullable()
->nullable()
);

jetpack_boost_register_action( 'page_cache_error', 'run-page-cache-setup', Schema::as_void(), new Run_Setup() );
jetpack_boost_register_action( 'page_cache', 'run-setup', Schema::as_void(), new Run_Setup() );

jetpack_boost_register_option(
'page_cache',
Expand Down

0 comments on commit 136ed52

Please sign in to comment.