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

Cloudflare purged several times on post update #6043

Closed
4 tasks
WordPresseur opened this issue Jul 13, 2023 · 6 comments · Fixed by #6050
Closed
4 tasks

Cloudflare purged several times on post update #6043

WordPresseur opened this issue Jul 13, 2023 · 6 comments · Fixed by #6050
Assignees
Labels
3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting effort: [XS] < 1 day of estimated development time priority: high Issues which should be resolved as quickly as possible type: enhancement Improvements that slightly enhance existing functionality and are fast to implement
Milestone

Comments

@WordPresseur
Copy link
Contributor

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

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

Describe the bug
When a post is updated, Cloudflare cache is purged 3 times:

  1. via WP_Rocket/ThirdParty/Plugins/CDN/Cloudflare: purge_cloudflare_partial
  2. via WP_Rocket/ThirdParty/Plugins/CDN/Cloudflare: purge_cloudflare_post
  3. via official Cloudflare plugin: https://github.com/cloudflare/Cloudflare-WordPress/blob/34852c089cb121860ecabd485120eb1c2fc4a286/cloudflare.loader.php#L113
    (or on the WordPress Repo: https://plugins.trac.wordpress.org/browser/cloudflare/trunk/cloudflare.loader.php#L113)

Expected behavior
Cloudflare cache should only be purged once.

Additional context
Ticket: https://secure.helpscout.net/conversation/2273098471/424855?folderId=1213662

Backlog Grooming (for WP Media dev team use only)

  • Reproduce the problem
  • Identify the root cause
  • Scope a solution
  • Estimate the effort
@piotrbak piotrbak added type: enhancement Improvements that slightly enhance existing functionality and are fast to implement 3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting priority: high Issues which should be resolved as quickly as possible needs: r&d Needs research and development (R&D) before a solution can be proposed and scoped. labels Jul 14, 2023
@piotrbak
Copy link
Contributor

piotrbak commented Jul 14, 2023

Not sure what will we be able to improve here, as per our past discussions. Let's revisit this part of the code and try to do the following:

Prerequisites: WP Rocket enabled, CF plugin enabled, APO activated for the domain

Acceptance Criteria:

  1. When updating the post, only two requests are being sent to APO (our and CF official one).*
  2. No regressions in the Purge URL and Purge Whole Cache parts, only one request should be sent too.
  • We can't make it to only one request for now, as CF Official plugin has a bug. We'll fix this whenever it's possible

@Tabrisrp
Copy link
Contributor

Tabrisrp commented Jul 17, 2023

We could remove the hook on after_clean_post, since rocket_clean_post() also uses rocket_clean_files(), so it will go through after_clean_files anyway.

If we remove our hooks entirely, it will allow to have only one request, but it might not cover all URLs to clean, as the CF plugin is not clearing as much as us. And as discussed earlier, their hooks are not implemented correctly so we can't add additional data to them.

@piotrbak
Copy link
Contributor

@Tabrisrp I'd split this ticket into two then:

  1. Removal of the after_clean_post hook
  2. Creating PR related to the Cloudflare + maybe adding a PR in their repository to speed up the process.

What do you think?

@piotrbak
Copy link
Contributor

So, in this PR we'll only remove the after_clean_post hook, I'll create an issue for the second iteration

@Tabrisrp
Copy link
Contributor

I would not have high expectations for the PR on their side, there is already an issue about it that was not solved since at least a couple years.

@Tabrisrp Tabrisrp added effort: [XS] < 1 day of estimated development time and removed needs: grooming needs: r&d Needs research and development (R&D) before a solution can be proposed and scoped. labels Jul 17, 2023
@Tabrisrp Tabrisrp self-assigned this Jul 17, 2023
@vmanthos
Copy link
Contributor

@Tabrisrp @piotrbak While doing exploratory for this issue, I found that rocket_clean_post() and rocket_clean_files() are called twice every time a post is updated. The same goes for after_rocket_clean_files. Although I haven't tested this with the PR this is likely involved in increasing the number of requests towards Cloudflare. Further R & D is required.

For future reference, the reason those functions run twice is because clean_post_cache fires twice.
Here is the log - wp_debug_backtrace_summary includes the backtrace for the clean_post_cache() method using wp_debug_backtrace_summary():

clean_post_cache() run
wp_debug_backtrace_summary: 'require(\'wp-blog-header.php\'), wp, WP->main, WP->parse_request, do_action_ref_array(\'parse_request\'), WP_Hook->do_action, WP_Hook->apply_filters, rest_api_loaded, WP_REST_Server->serve_request, WP_REST_Server->dispatch, WP_REST_Server->respond_to_request, WP_REST_Posts_Controller->update_item, wp_update_post, wp_insert_post, clean_post_cache'

13:12:45 clean_post_cache fired
===== rocket_clean_files() =====
array (
  0 => 'https://wprocketest.test/hello-world',
  1 => 'https://wprocketest.test/blog',
  2 => 'https://wprocketest.test/author/vasilis/',
)

===== rocket_clean_post() =====
array (
  0 => 'https://wprocketest.test/hello-world',
  1 => 'https://wprocketest.test/blog',
  2 => 'https://wprocketest.test/author/vasilis/',
)

clean_post_cache run
wp_debug_backtrace_summary: 'edit_post, wp_update_post, wp_insert_post, clean_post_cache'


13:12:45 clean_post_cache fired
===== rocket_clean_files() =====
array (
  0 => 'https://wprocketest.test/hello-world',
  1 => 'https://wprocketest.test/blog',
  2 => 'https://wprocketest.test/post-53',
  3 => 'https://wprocketest.test/post-2',
  4 => 'https://wprocketest.test/gallery-layout',
  5 => 'https://wprocketest.test/author/vasilis/',
)

===== rocket_clean_post() =====
array (
  0 => 'https://wprocketest.test/hello-world',
  1 => 'https://wprocketest.test/blog',
  2 => 'https://wprocketest.test/post-53',
  3 => 'https://wprocketest.test/post-2',
  4 => 'https://wprocketest.test/gallery-layout',
  5 => 'https://wprocketest.test/author/vasilis/',
)

github-merge-queue bot pushed a commit that referenced this issue Jul 28, 2023
… a post (#6050)

Co-authored-by: Vasilis Manthos <vmanthos@gmail.com>
@piotrbak piotrbak added this to the 3.14.3 milestone Jul 28, 2023
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 effort: [XS] < 1 day of estimated development time priority: high Issues which should be resolved as quickly as possible type: enhancement Improvements that slightly enhance existing functionality and are fast to implement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants