Make sure that we cache only valid posts/pages urls
Description
Fixes https://github.com/wp-media/wp-rocket.me/issues/4456
This PR will make sure that we cache only
Type of change
- [x] Bug fix (non-breaking change which fixes an issue).
- [x] Enhancement (non-breaking change which improves an existing functionality).
Detailed scenario
For posts, pages, and even custom posts in some cases when we add any string inside the url, we still cache those pages because they don't return 404 error, here we make sure that those urls are not cached at all.
More details are inside the issue itself.
Technical description
Documentation
We compare the current page/post urls with their correct urls and stop caching for those not valid ones.
New dependencies
No
Risks
We have this code exactly like what we handled taxonomies so I hope we don't have a false cases that we detect the valid urls correctly.
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.
Unticked items justification
Checking tests now.
Additional Checks
- [ ] In the case of complex code, I wrote comments to explain it.
- [ ] When possible, I prepared ways to observe the implemented system (logs, data, etc.).
- [ ] 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 |
|---|---|
| :white_check_mark: +0.01% (target: -0.10%) | :white_check_mark: 56.67% (target: 50.00%) |
Coverage variation details
| Coverable lines | Covered lines | Coverage | |
|---|---|---|---|
| Common ancestor commit (28661bd9cd542cfa85d7ea0e3bfb880f68f28f0d) | 39725 | 17535 | 44.14% |
| Head commit (dd636c95574874a8b3f32d96086c4244fb3b5245) | 39749 (+24) | 17548 (+13) | 44.15% (+0.01%) |
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 (#7236) | 30 | 17 | 56.67% |
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
I think we need to wait a bit before merging this PR because we got some issues with taxonomy pages PR and the solution here is exactly the same.
Those issues are:
- When using custom permalink that mentioned as
second issueIn this PR description - When using custom rewrite rules as mentioned in the last dev escalation with an example here
but now this will happen with posts so I'd suggest having a filter to enable/disable this feature when needed (that's a product decision)
CC @MathieuLamiot
In general, we'll need a filter here and some more testing as we know about the new limitations
Definitely, let's go with adding a filter around this whole functionality once 3.19-prealpha is released internally 👌
@wordpressfan I did a refactor and added the filter if you want to have a look
Everything green, Report here
https://group-onecom.slack.com/archives/C08F4LZB2QG/p1748975372073809 moved to 3.19.1