wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

Some transients aren't deleted after deleting WP Rocket

Open Mai-Saad opened this issue 2 years ago • 1 comments

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

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

Describe the bug Some WPR transients aren't deleted after deleting the plugin

To Reproduce Steps to reproduce the behavior:

  1. Activate WPR and enable all options
  2. Deactivate the plugin
  3. Delete plugin
  4. Check transients

Expected behavior Transients are deleted when deleting the plugin

Screenshots If applicable, add screenshots to help explain your problem. Screenshot from 2022-04-19 10-27-20

Backlog Grooming (for WP Media dev team use only)

  • [ ] Reproduce the problem
  • [ ] Identify the root cause
  • [ ] Scope a solution
  • [ ] Estimate the effort

Mai-Saad avatar Apr 19 '22 08:04 Mai-Saad

Additionally to the transients that Mai listed this one is not deleted as well: wpr_dashboard_seen_

The same goes for the following option: rocket_cache_dir_size_check

vmanthos avatar Sep 16 '22 12:09 vmanthos

This too wpr_dynamic_lists_delayjs is not deleted

Mai-Saad avatar Jan 13 '23 10:01 Mai-Saad

The following as well:

  • timeout_wp_rocket_pricing
  • wp_rocket_pricing
  • wp_rocket_last_base_url
  • timeout_rocket_mod_pagespeed_enabled

vmanthos avatar Feb 06 '23 13:02 vmanthos

cloudflare_update_settings isn't deleted as well. https://github.com/wp-media/wp-rocket/blob/8befdf3f22a901749dfcdd6a1a0c980530f0d120/inc/Addon/Cloudflare/Subscriber.php#L559 https://github.com/wp-media/wp-rocket/blob/8befdf3f22a901749dfcdd6a1a0c980530f0d120/inc/Addon/Cloudflare/Subscriber.php#L574

vmanthos avatar Apr 28 '23 11:04 vmanthos

Reproduce the problem ✅

Did not reproduce the problem as the cause is clearly visible in the code.

Identify the root cause ✅

The identified transients in the screenshot above are not added to the array here: https://github.com/wp-media/wp-rocket/blob/8b64400a9c36ec5c0a26df238946cea389fc2a34/inc/Engine/WPRocketUninstall.php#L47

Scope a solution ✅

Add the following transients to the array here rocket_rucss_processing rocket_mod_pagespeed_enabled wp_rocket_pricing rocket_get_refreshed_fragments_cache

For dynamic transients like wpr_dashboard_seen_ and _cloudflare_update_settings we can delete them by doing a direct query with a wildcard on the db using wpdb

Estimate the effort ✅ [XS]

jeawhanlee avatar Jan 15 '24 10:01 jeawhanlee

Is the use of wpdb and wildcard a good idea ? We aren't using much wpdb within the plugin itself, and the wildcard is a bit too general, even tho names of the transient are specific.

For the _cloudflare_update_settings transient, I thought about this solution:

foreach (get_users() as $user) {
	delete_transient($user->ID . '_cloudflare_update_settings');
}

But in case of a website with tons of users, it wouldn't be a good idea to do a loop. @Tabrisrp What do you think ? Is the use of wpdb and a wildcard okay ?

Miraeld avatar Jan 16 '24 14:01 Miraeld

Yes it is, it is used in core for example to delete expired transients (https://developer.wordpress.org/reference/functions/delete_expired_transients/)

We can use the transient prefix + the name and it will only match what we need to delete.

remyperona avatar Jan 16 '24 15:01 remyperona