-
Notifications
You must be signed in to change notification settings - Fork 815
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
Boost: Implement Cache Preloading - Version One #41988
base: trunk
Are you sure you want to change the base?
Boost: Implement Cache Preloading - Version One #41988
Conversation
Co-authored-by: Peter Petrov <[email protected]>
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Boost plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCannot generate coverage summary while tests are failing. 🤐 Please fix the tests, or re-run the Code coverage job if it was something being flaky. Full summary · PHP report · JS report Coverage check overridden by
Coverage tests to be added later
|
…date mechanism - Refactor preload mechanism to support dynamic post scheduling - Add method to handle post updates and schedule preloading for cornerstone pages - Implement more flexible preload post tracking using WordPress options - Improve error handling during page preloading
- Add new method `is_cornerstone_page_by_url()` in Cornerstone_Utils to check cornerstone pages by URL - Modify `is_cornerstone_page()` to use the new URL-based method - Update Cache_Preload to handle cache invalidation and preloading of cornerstone pages - Add action hook for successful cache invalidation - Improve method names and add comments for clarity
- Enhance `handle_cache_invalidation()` method to support different cache invalidation types - Add support for full cache deletion by preloading all Cornerstone Pages - Improve documentation with detailed comments and @SInCE tags - Update method signature to include invalidation type parameter - Refactor cache preloading logic for more robust handling of cache events
// Clear the preload posts so they're not preloaded again. | ||
$this->set_posts_to_preload( array() ); | ||
|
||
foreach ( $posts as $post ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should limit how many pages/posts are being preloaded here within the cron to prevent potentially overloading the site. Theoritically the limit of URLs should only be 10 as that's our current Cornerstone Page limit.
We could only preload 10 URLs at a time, and then schedule another cron job after 2 seconds to repeat the same.
Not sure if it's worth doing now, or wait until Version 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented this now with batching, as seen below:
jetpack/projects/plugins/boost/app/modules/optimizations/page-cache/Cache_Preload.php
Lines 145 to 172 in cc070a2
/** | |
* Prepares the next batch of URLs to preload. | |
* | |
* Takes the full list of posts to preload, extracts the first batch, | |
* updates the preload queue, and schedules the next run if needed. | |
* | |
* @since $$next-version$$ | |
* @param array $posts Full list of posts to preload. | |
* @return array The batch of posts to process now. | |
*/ | |
private function prepare_next_batch( $posts ) { | |
// Process in batches of 10 to reduce server load | |
$batches = array_chunk( $posts, 10 ); | |
$current_batch = array_shift( $batches ); | |
// Calculate remaining posts | |
$remaining = $this->flatten_batches( $batches ); | |
// Update the preload queue | |
$this->set_posts_to_preload( $remaining ); | |
// Schedule the next batch if needed | |
if ( ! empty( $remaining ) ) { | |
$this->schedule_preload_cronjob(); | |
} | |
return $current_batch; | |
} |
- Refactor page preloading to process URLs in batches of 10 - Add batch processing to reduce server load and improve reliability - Enhance error handling with detailed logging for preload failures - Improve HTTP response validation during page preloading - Add methods to manage batch processing and track remaining URLs
- Create new test suite for Cache_Preload class in Jetpack Boost - Implement comprehensive test coverage for cache preloading methods - Test scenarios including cornerstone page preloading, cache invalidation, and scheduling - Verify interactions with WordPress core functions and utility classes - Ensure robust testing of preload scheduling, post update handling, and cache management
- Refactor test cases to use direct method calls instead of partial mocks - Replace Mockery-based mocking with explicit WordPress function expectations - Improve test coverage by directly testing Cache_Preload class methods - Simplify test setup and reduce complexity of test assertions - Ensure consistent testing approach for cache preloading functionality
- Enhance page preloading by adding cache-control headers
Fixes
#42111
Proposed changes:
Cache_Preload.php
to handle cache preloading logic (Submodule of Page Cache)invalidate
method inFile_Storage.php
with better action handlingOther information:
Jetpack product discussion
pc9hqz-3nV-p2
Does this pull request change what data or activity we track or use?
N/A
Testing instructions:
1. Saving Cornerstone Pages list, Clearing Page Cache
Instructions
Before Applying Branch
./wp-content/boost-cache/cache/(domain)
./wp-content/boost-cache/cache/(domain)
After Applying Branch
./wp-content/boost-cache/cache/(domain)
2. Updating Cornerstone Page
Instructions
Before Applying Branch
./wp-content/boost-cache/cache/(domain)
./wp-content/boost-cache/cache/(domain)
After Applying Branch
./wp-content/boost-cache/cache/(domain)