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

Partial purge does not clear CPT archive when non-default cache files are used #4508

Closed
4 tasks
Mai-Saad opened this issue Nov 16, 2021 · 12 comments · Fixed by #7277
Closed
4 tasks

Partial purge does not clear CPT archive when non-default cache files are used #4508

Mai-Saad opened this issue Nov 16, 2021 · 12 comments · Fixed by #7277
Assignees
Labels
3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting module: cache priority: medium Issues which are important, but no one will go out of business. severity: moderate Feature isn't working as expected but has work around to get same value type: bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@Mai-Saad
Copy link
Contributor

Mai-Saad commented Nov 16, 2021

Before submitting an issue please check that you’ve completed the following steps:

  • Made sure you’re on the latest version => 3.10.3
  • Used the search feature to ensure that the bug hasn’t been reported before

Describe the bug
Some Cached pages aren't cleared when editing post if Cookie GDPR is enabled

To Reproduce
Precondition:

  • Cookie Notice & Compliance for GDPR / CCPA is enabled
  • WooCommerce is enabled, at least one product is present, shop page is set

Steps to reproduce the behavior:

  1. Visit the following URLs:
    https://rocketlabsqa.ovh/product/wordpress-pennant/
    https://rocketlabsqa.ovh/shop/
  2. Accept cookie and refresh both pages
  3. Edit the post and update:
    https://rocketlabsqa.ovh/wp-admin/post.php?post=1000&action=edit
  4. Cached files for the shop are not deleted

Expected behavior
All cached files are deleted

Screenshots
If applicable, add screenshots to help explain your problem.
cache

Additional context

Backlog Grooming (for WP Media dev team use only)

  • Reproduce the problem
  • Identify the root cause
  • Scope a solution
  • Estimate the effort
@Mai-Saad Mai-Saad added type: bug Indicates an unexpected problem or unintended behavior 3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting module: cache priority: low Issues that can wait severity: moderate Feature isn't working as expected but has work around to get same value labels Nov 16, 2021
@Mai-Saad Mai-Saad changed the title Some pages cache aren't cleared when Cookie GDPR is enabled Some pages cache aren't cleared when edit post while Cookie GDPR is enabled Nov 16, 2021
@webtrainingwheels
Copy link

webtrainingwheels commented Dec 28, 2021

This is not specific to Cookie GDPR but will happen whenever we create any non-default cache files. So it happens when WebP is active also, for example. @Mai-Saad maybe you could update the title to make it more general?

This is also related to: #2068

@Mai-Saad Mai-Saad changed the title Some pages cache aren't cleared when edit post while Cookie GDPR is enabled Partial purge does not clear CPT archive when non-default cache files are used Jan 6, 2022
@Mai-Saad
Copy link
Contributor Author

Mai-Saad commented Jan 6, 2022

another scenario with WebP here #4617

@piotrbak
Copy link
Contributor

There's no feedback from customers regarding this one. It's not going to be implemented in the near future. We're open to discuss and reopen the issue though.

@piotrbak piotrbak closed this as not planned Won't fix, can't repro, duplicate, stale Jun 26, 2024
@vellebelle
Copy link

I am having the same problem and was advised to install an extra plugin from WP Rocket to solve the issue. Why can't you add it to the core of WP Rocket as others are experiencing the same problem?

@piotrbak piotrbak reopened this Nov 5, 2024
@worldwildweb
Copy link
Contributor

related https://secure.helpscout.net/conversation/2819097199/534966
When a new custom post is created, if cached files exist, the archived desktop page is cleared, but the mobile page is not cleared.

@piotrbak piotrbak added priority: medium Issues which are important, but no one will go out of business. and removed priority: low Issues that can wait labels Jan 22, 2025
@piotrbak piotrbak added this to the 3.18.2 milestone Jan 26, 2025
@piotrbak
Copy link
Contributor

Acceptance Criteria
When Partial Purge is happening, we need to make sure to clear cache of the archives:

  1. mobile cache files
  2. webp cache files
  3. dynamic cookies cache files
  4. all combinations of the aboves

@Miraeld
Copy link
Contributor

Miraeld commented Jan 29, 2025

Scope a solution

To fix the mentioned issue, we could modify the $purge_urls[] = part to include other files to be deleted.
I also recommend optimising it.

if ( 'post' !== $post_type ) {
    $post_type_archive = get_post_type_archive_link( $post_type );

    if ( $post_type_archive ) {
        // Define base filename and SSL suffix
        $base_filename = 'index';
        $ssl_suffix = is_ssl() ? '-https' : '';

        $post_type_archive = trailingslashit( $post_type_archive );

        // Define base cache variations
        $filenames = [
            "{$base_filename}{$ssl_suffix}.html",
            "{$base_filename}{$ssl_suffix}.html_gzip",
            "{$base_filename}-mobile{$ssl_suffix}.html",
            "{$base_filename}-mobile{$ssl_suffix}.html_gzip",
            "{$base_filename}{$ssl_suffix}-true.html",
            "{$base_filename}{$ssl_suffix}-true.html_gzip",
            $GLOBALS['wp_rewrite']->pagination_base
        ];

        // Add full URLs to the purge array
        $purge_urls = array_map(fn($file) => $post_type_archive . $file, $filenames);
    }
}

This will include the -true.html, -true.html_gzip & -mobile files.

This goes to replace the current code here

@Miraeld Miraeld self-assigned this Jan 29, 2025
@wordpressfan
Copy link
Contributor

Checking that now...

@wordpressfan
Copy link
Contributor

@Miraeld what happens when we add the following line:

$purge_urls[]      = $post_type_archive;

directly after this line:

$purge_urls[] = $post_type_archive . $GLOBALS['wp_rewrite']->pagination_base;

can u plz check if this would work or not?

@Miraeld
Copy link
Contributor

Miraeld commented Jan 30, 2025

Umm, it seems to work, but, there is something I don't get.
If I add a log to $post_type_archive, it is equal to: https://new.rocketlabsqa.ovh/shop-3 while I'm saving the page https://new.rocketlabsqa.ovh/product/resume-promo

Is it expected @wordpressfan ?

@wordpressfan
Copy link
Contributor

Yes this is normal, if you checked the woocommerce Settings > Products the setting of Shop page, you will find the mentioned page shop-3 with the ID 12034 for this specific site.

We use the function get_post_type_archive_link to get the custom post type archive's page which is set by woocommerce itself, exactly here:

https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/class-wc-post-types.php#L369

which is set here:

https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/class-wc-post-types.php#L309

you can read more about has_archive argument here:

https://developer.wordpress.org/reference/functions/register_post_type/#parameters

does this make sense?
If that's working with u, do u mind updating the grooming to send it to Todo column?

Thanks Boss.

@wordpressfan
Copy link
Contributor

Grooming

We need to add the following line:

$purge_urls[]      = $post_type_archive;

directly after this line:

$purge_urls[] = $post_type_archive . $GLOBALS['wp_rewrite']->pagination_base;

Effort:

[XS]

@wordpressfan wordpressfan self-assigned this Feb 6, 2025
@Mai-Saad Mai-Saad self-assigned this Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting module: cache priority: medium Issues which are important, but no one will go out of business. severity: moderate Feature isn't working as expected but has work around to get same value type: bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants