Don't cache not valid taxonomy frontend pages and stop applying optimizations
Description
Fixes https://github.com/wp-media/wp-rocket.me/issues/4164
In this pull request, we are checking if the current frontend page is a taxonomy page and it has a not valid url schema, then we disable this page's caching, also stop applying all optimizations there.
Type of change
- [x] Bug fix (non-breaking change which fixes an issue).
- [x] Breaking change (fix or feature that would cause existing functionality to not work as before).
Detailed scenario
As mentioned in the issue itself:
if i visit wordpress.org at: https://wordpress.org/news/category/releases/ i get a response 200 and see the content.
Then again if i change the url so the last part still exists, something like: https://wordpress.org/news/category/i_just_added_something_here/releases/
Technical description
Documentation
Here we get all public taxonomies that have UI pages and compare the current page's query var with the taxonomies query vars.
We provided also a filter rocket_cache_taxonomy_query_vars so we can include or exclude taxonomy query vars from that functionality.
New dependencies
No
Risks
The only thing that I can think of, is that we will prevent those pages from being cached as they were already cached but that's to fix the mentioned issue.
Also for @wp-media/qa-team,
In this PR, we also added a change to check if the rocket_buffer filter returns empty HTML, then we will revert back to the main page's HTML, so if you used the following snippet as an example:
add_filter( 'rocket_buffer', function ( $html ) {
return '';
} );
Before this PR, the page will be blank, but with this PR, we will show the not optimized page.
Mandatory Checklist
Code validation
- [x] I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
- [x] I triggered all changed lines of code at least once without new errors/warnings/notices.
- [x] I implemented built-in tests to cover the new/changed code.
Code style
- [x] I wrote a self-explanatory code about what it does.
- [x] I protected entry points against unexpected inputs.
- [x] I did not introduce unnecessary complexity.
- [x] Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.
Additional Checks
- [x] In the case of complex code, I wrote comments to explain it.
- [x] When possible, I prepared ways to observe the implemented system (logs, data, etc.).
- [x] I added error handling logic when using functions that could throw errors (HTTP/API request, filesystem, etc.)
Coverage summary from Codacy
See diff coverage on Codacy
| Coverage variation | Diff coverage |
|---|---|
| Report missing for 8b46e6b8692f3b80931d352eaee78481fa5467e6[^1] | :white_check_mark: 51.85% (target: 50.00%) |
Coverage variation details
| Coverable lines | Covered lines | Coverage | |
|---|---|---|---|
| Common ancestor commit (8b46e6b8692f3b80931d352eaee78481fa5467e6) | Report Missing | Report Missing | Report Missing |
| Head commit (d01ebd7d48e1fd2b64a001c4e8dfa5ab6d1757dc) | 37781 | 16617 | 43.98% |
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>
Diff coverage details
| Coverable lines | Covered lines | Diff coverage | |
|---|---|---|---|
| Pull request (#6984) | 27 | 14 | 51.85% |
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%
See your quality gate settings Change summary preferences
Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more [^1]: Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.
@wordpressfan I think the changes look good to fix the issue at hand, are you waiting for something before moving it forward to review?
This PR was a POC to validate the idea, so it needs to be adapted to be a real PR, like fixing phpcs and tests.
I'm working on tests now