PluginProbe
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score / trunk
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score vtrunk
trunk 1.0 1.0.1 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1 2.1.1 2.1.2 2.2 2.2.1 All 69 releases
← All changes | includes/classes/Async/DatabaseOptimizer.php +31 -5 2.0trunk View file →
@@ -9,8 +9,12 @@
9 9
10 10 use const PoweredCache\Constants\DB_CLEANUP_COUNT_CACHE_KEY;
11 11 use \Powered_Cache_WP_Background_Process as Powered_Cache_WP_Background_Process;
12 12
13 +// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
14 +// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
15 +
16 +
13 17 /**
14 18 * Class DatabaseOptimizer
15 19 */
16 20 class DatabaseOptimizer extends Powered_Cache_WP_Background_Process {
@@ -177,11 +181,31 @@
177 181 $query = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%_transient_%'" );
178 182 if ( $query ) {
179 183 foreach ( $query as $transient ) {
180 184 if ( strpos( $transient, '_site_transient_' ) !== false ) {
181 - delete_site_transient( str_replace( '_site_transient_', '', $transient ) );
185 + $transient = str_replace( '_site_transient_', '', $transient );
186 + delete_site_transient( $transient );
187 + if ( wp_using_ext_object_cache() ) { // make sure transients deleted from db
188 + $option_timeout = '_site_transient_timeout_' . $transient;
189 + $option = '_site_transient_' . $transient;
190 + $result = delete_site_option( $option );
191 +
192 + if ( $result ) {
193 + delete_site_option( $option_timeout );
194 + }
195 + }
182 196 } else {
183 - delete_transient( str_replace( '_transient_', '', $transient ) );
197 + $transient = str_replace( '_transient_', '', $transient );
198 + delete_transient( $transient );
199 + if ( wp_using_ext_object_cache() ) { // make sure transients deleted from db
200 + $option_timeout = '_transient_timeout_' . $transient;
201 + $option = '_transient_' . $transient;
202 + $result = delete_option( $option );
203 +
204 + if ( $result ) {
205 + delete_option( $option_timeout );
206 + }
207 + }
184 208 }
185 209 }
186 210 }
187 211 break;
@@ -188,9 +212,11 @@
188 212 case 'db_cleanup_optimize_tables':
189 213 $query = $wpdb->get_results( $wpdb->prepare( "SELECT table_name, data_free FROM information_schema.tables WHERE table_schema = %s and Engine <> 'InnoDB' and data_free > 0", DB_NAME ) );
190 214 if ( $query ) {
191 215 foreach ( $query as $table ) {
192 - $wpdb->query( "OPTIMIZE TABLE $table->table_name" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
216 + if ( ! empty( $table->table_name ) ) {
217 + $wpdb->query( 'OPTIMIZE TABLE `' . esc_sql( $table->table_name ) . '`' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
218 + }
193 219 }
194 220 }
195 221 break;
196 222 }
@@ -199,9 +225,9 @@
199 225 }
200 226
201 227 /**
202 228 * Sometimes canceling a process is glitchy
203 - * Try to cancell all items in the queue up to $max_attempt
229 + * Try to cancel all items in the queue up to $max_attempt
204 230 */
205 231 public function cancel_process() {
206 232 $max_attempt = 5;
207 233 $cancelled = 0;
@@ -208,9 +234,9 @@
208 234 while ( ! parent::is_queue_empty() ) {
209 235 if ( $cancelled >= $max_attempt ) {
210 236 break;
211 237 }
212 - parent::cancel_process();
238 + parent::cancel();
213 239 $cancelled ++;
214 240 }
215 241 }
216 242