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

Avoid clearing cache once per language #6214

Closed
piotrbak opened this issue Oct 10, 2023 · 4 comments · Fixed by #6263
Closed

Avoid clearing cache once per language #6214

piotrbak opened this issue Oct 10, 2023 · 4 comments · Fixed by #6263
Assignees
Labels
3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting effort: [S] 1-2 days of estimated development time module: cache priority: medium Issues which are important, but no one will go out of business. type: enhancement Improvements that slightly enhance existing functionality and are fast to implement
Milestone

Comments

@piotrbak
Copy link
Contributor

piotrbak commented Oct 10, 2023

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
WPML Team reported that when translating a single post we're clearing the cache once per language. It's possible to do it only once to avoid resources problems.

To Reproduce
Included in #6214 (comment)

Expected behavior
Included in #6214 (comment)

Acceptance Criteria (for WP Media team use only)

  • We should launch rocket_clean_domain only once, not once per language
  • No regression at clearing the translated posts
  • No regression at clearing the specific languages
@piotrbak piotrbak added waiting for feedback 3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting labels Oct 10, 2023
@zeopix
Copy link

zeopix commented Oct 11, 2023

Thanks for creating this ticket @piotrbak .

You can reproduce this issue with some simple steps:

  • Create a clean WP site.
  • Add WPML Plugin, register it, add few languages.
  • Install WP Rocket, go to Settings > Wp Rocket > Cache > "Enable cache for logged-in wordpress users".
  • In the following request, the problem already occurs.
  • It can also occur when applying a translation, and many other cinrcumstances (whatever hook ends up calling rocket_clean_domain in inc/functions/files.php).

The problem is because in this method, the cache is cleared for each $url, and $url is retrieved using the function get_rocket_i18n_uri or get_rocket_i18n_home_url, which retrieves one URL per language.
This seems fine because some hooks are fired per URL, this logic seems to be correct, but later, a hook after_rocket_clean_domain is fired per URL, which is bound to clear_full_cache hook.

This later one, will do the same query on every step, so we propose to extract this hook from the foreach ( $urls as $url ) {

(Se how we tweaked this function in this gist)

An update query like this on every row of the wpv_table, repeated n times (where n=number of languages) locks this table and saturates mysql in large sites causing a significant performance impact.

@piotrbak piotrbak added type: enhancement Improvements that slightly enhance existing functionality and are fast to implement module: cache priority: medium Issues which are important, but no one will go out of business. needs: grooming and removed waiting for feedback labels Oct 23, 2023
@Tabrisrp
Copy link
Contributor

Scope a solution ✅

We can add a new filter outside of the loop rocket_after_clean_domain, and update the hook used in the preload subscriber (Could be also good to investigate other usages of the after_rocket_clean_domain filter to see if they could be changed and reduce the number of calls to the hooked methods).

Estimate the effort ✅

Effort [S]

@Tabrisrp Tabrisrp added effort: [S] 1-2 days of estimated development time and removed needs: grooming labels Oct 23, 2023
@CrochetFeve0251
Copy link
Contributor

Seems good to me

@wordpressfan
Copy link
Contributor

Small discussion: https://wp-media.slack.com/archives/CUT7FLHF1/p1698656302149819

We need to create a new action not filter exactly here:

@wordpressfan wordpressfan self-assigned this Nov 7, 2023
@Mai-Saad Mai-Saad added this to the 3.15.5 milestone Nov 20, 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: [S] 1-2 days of estimated development time module: cache priority: medium Issues which are important, but no one will go out of business. 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.

6 participants