Skip to content
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

Clear CPT custom cache files correctly #7277

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

wordpressfan
Copy link
Contributor

@wordpressfan wordpressfan commented Feb 6, 2025

Description

Fixes #4508

This PR makes sure that we remove all custom cache files for custom post types are deleted properly.

Type of change

  • Bug fix (non-breaking change which fixes an issue).

Detailed scenario

When we clear custom post type post (with any clearance action like editing the post), we should clear the archive page (shop page for woocommerce product CPT as an example), but when we have webp enabled (or any feature that creates custom cache file other than index.html or index.html_gzip) those custom cache files are kept there without being removed.

Steps to reproduce:

  1. Install/activate woocommerce
  2. Change the permalink structure for produce to be like:
    image
  3. Make sure that some products' pages along with shop page are cached.
  4. Make sure that preload is disabled.
  5. Update one post.
  6. The pages that should be cleared are as follows:-
  7. Category page
  8. Edited Product page
  9. Previous, Next, Previous in the same category, and next in the same category.
  10. Shop page
  11. Other than that all pages below shop folder shouldn't be touched.

Technical description

Documentation

Here we added the support of regex inside filenames to target all html files from the selected directory, this will make sure that we will remove the files from the directory without affecting any other directories inside this one.

New dependencies

N/A

Risks

we should be good but as we remove with regex we need to test that to make sure that we only remove what is needed to be removed.

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

Unticked items justification

All good.

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.)

@wordpressfan wordpressfan self-assigned this Feb 6, 2025
@wordpressfan wordpressfan marked this pull request as ready for review February 6, 2025 00:28
Copy link

codacy-production bot commented Feb 6, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for a0ceecd1 26.67% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (a0ceecd) Report Missing Report Missing Report Missing
Head commit (b73dc83) 38809 17165 44.23%

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 (#7277) 15 4 26.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

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Footnotes

  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 wordpressfan requested a review from a team February 6, 2025 00:36
@Mai-Saad
Copy link
Contributor

Mai-Saad commented Feb 7, 2025

@wordpressfan Thanks for the PR. please note that we have the following regression
1- product permalink is shop base
2- cache shop , product 1, product 2
3- edit product 1 or clear cache of product 1 from page edit
4- all shop folder is deleted including product 2 cache ==> on trunk product 2 isnot touched

@remyperona
Copy link
Contributor

If you do it that way, you're going to delete cache of any child item in the permalink structure, that's why the deletion is not using the base but the filenames.

You need a different approach to handle the different cache files variations. Possibly with RegEx if it's usable (I don't remember right now), you could do something like index(.*).html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Partial purge does not clear CPT archive when non-default cache files are used
4 participants