From 4d07ba367474ca44be8af4e1879c8d216ef01382 Mon Sep 17 00:00:00 2001 From: Ahmed Saeed Date: Thu, 14 Sep 2023 21:49:56 +0300 Subject: [PATCH 1/3] adding the grooming code --- inc/Engine/Cache/PurgeActionsSubscriber.php | 16 +++++++++++++++- .../Optimization/DynamicLists/DynamicLists.php | 9 ++++++--- .../DynamicLists/ServiceProvider.php | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/inc/Engine/Cache/PurgeActionsSubscriber.php b/inc/Engine/Cache/PurgeActionsSubscriber.php index fc40be7392..6f07bc4ac3 100644 --- a/inc/Engine/Cache/PurgeActionsSubscriber.php +++ b/inc/Engine/Cache/PurgeActionsSubscriber.php @@ -54,7 +54,7 @@ public static function get_subscribed_events() { ], 'rocket_rucss_complete_job_status' => [ 'purge_url_cache', 100 ], 'rocket_rucss_after_clearing_usedcss' => 'purge_url_cache', - 'rocket_after_save_dynamic_lists' => 'purge_cache', + 'rocket_after_save_dynamic_lists' => 'purge_cache_after_saving_dynamic_lists', 'update_option_' . $slug => [ 'purge_cache_reject_uri_partially', 10, 2 ], 'update_option_blog_public' => 'purge_cache', ]; @@ -179,4 +179,18 @@ public function purge_cache() { public function purge_cache_reject_uri_partially( array $old_value, array $value ): void { $this->purge->purge_cache_reject_uri_partially( $old_value, $value ); } + + /** + * Purge cache after saving dynamic lists. + * + * @param bool $should_purge Should purge or not. + * + * @return void + */ + public function purge_cache_after_saving_dynamic_lists( $should_purge = true ) { + if ( ! $should_purge ) { + return; + } + $this->purge_cache(); + } } diff --git a/inc/Engine/Optimization/DynamicLists/DynamicLists.php b/inc/Engine/Optimization/DynamicLists/DynamicLists.php index a2f63edbb3..cf0d4be207 100644 --- a/inc/Engine/Optimization/DynamicLists/DynamicLists.php +++ b/inc/Engine/Optimization/DynamicLists/DynamicLists.php @@ -102,8 +102,9 @@ public function update_lists_from_remote() { ]; } - $response = []; - $success = false; + $response = []; + $success = false; + $should_purge = false; foreach ( $this->providers as $provider ) { $result = $provider->api_client->get_exclusions_list( $provider->data_manager->get_lists_hash() ); @@ -141,6 +142,8 @@ public function update_lists_from_remote() { 'data' => '', 'message' => __( 'Lists are successfully updated.', 'rocket' ), ]; + + $should_purge |= $provider->clear_cache ?? true; } if ( $success ) { @@ -149,7 +152,7 @@ public function update_lists_from_remote() { * * @since 3.12.1 */ - do_action( 'rocket_after_save_dynamic_lists' ); + do_action( 'rocket_after_save_dynamic_lists', $should_purge ); } return $response; diff --git a/inc/Engine/Optimization/DynamicLists/ServiceProvider.php b/inc/Engine/Optimization/DynamicLists/ServiceProvider.php index dd141f9f02..99f2494880 100644 --- a/inc/Engine/Optimization/DynamicLists/ServiceProvider.php +++ b/inc/Engine/Optimization/DynamicLists/ServiceProvider.php @@ -70,6 +70,7 @@ public function register() { 'api_client' => $this->getContainer()->get( 'dynamic_lists_incompatible_plugins_lists_api_client' ), 'data_manager' => $this->getContainer()->get( 'dynamic_lists_incompatible_plugins_lists_data_manager' ), 'title' => __( 'Incompatible plugins Lists', 'rocket' ), + 'clear_cache' => true, ], ]; From 455477d0c24e9dbb1c0a8dec20cbea352358350b Mon Sep 17 00:00:00 2001 From: Ahmed Saeed Date: Tue, 19 Sep 2023 15:48:55 +0300 Subject: [PATCH 2/3] change clear cache argument for in compatible plugins to be false --- inc/Engine/Optimization/DynamicLists/ServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/Engine/Optimization/DynamicLists/ServiceProvider.php b/inc/Engine/Optimization/DynamicLists/ServiceProvider.php index 99f2494880..59e9059ed6 100644 --- a/inc/Engine/Optimization/DynamicLists/ServiceProvider.php +++ b/inc/Engine/Optimization/DynamicLists/ServiceProvider.php @@ -70,7 +70,7 @@ public function register() { 'api_client' => $this->getContainer()->get( 'dynamic_lists_incompatible_plugins_lists_api_client' ), 'data_manager' => $this->getContainer()->get( 'dynamic_lists_incompatible_plugins_lists_data_manager' ), 'title' => __( 'Incompatible plugins Lists', 'rocket' ), - 'clear_cache' => true, + 'clear_cache' => false, ], ]; From 02e32aeaab57c028d46b42fd11d2f4fa46c2c16f Mon Sep 17 00:00:00 2001 From: Ahmed Saeed Date: Wed, 20 Sep 2023 16:39:35 +0300 Subject: [PATCH 3/3] add the param to the hook docblock --- inc/Engine/Optimization/DynamicLists/DynamicLists.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inc/Engine/Optimization/DynamicLists/DynamicLists.php b/inc/Engine/Optimization/DynamicLists/DynamicLists.php index cf0d4be207..a43b4ac24e 100644 --- a/inc/Engine/Optimization/DynamicLists/DynamicLists.php +++ b/inc/Engine/Optimization/DynamicLists/DynamicLists.php @@ -151,6 +151,8 @@ public function update_lists_from_remote() { * Fires after saving all dynamic lists files. * * @since 3.12.1 + * + * @param bool $should_purge Should purge status based on the updated providers. */ do_action( 'rocket_after_save_dynamic_lists', $should_purge ); }