| @@ -292,16 +292,33 @@ | ||
| 292 | 292 | */ |
| 293 | 293 | private function wpp_tables_exist(): bool { |
| 294 | 294 | global $wpdb; |
| 295 | 295 | |
| 296 | + $tables = array( | |
| 297 | + $wpdb->prefix . 'popularpostsdata', | |
| 298 | + $wpdb->prefix . 'popularpostssummary', | |
| 299 | + ); | |
| 300 | + $key = implode( '|', $tables ); | |
| 301 | + static $cache = array(); | |
| 302 | + | |
| 303 | + if ( array_key_exists( $key, $cache ) ) { | |
| 304 | + return $cache[ $key ]; | |
| 305 | + } | |
| 306 | + | |
| 296 | 307 | $tables_exist = true; |
| 308 | + foreach ( $tables as $table ) { | |
| 309 | + $query = $wpdb->prepare( 'SELECT 1 FROM %i LIMIT 0', $table ); | |
| 310 | + $suppress_errors = $wpdb->suppress_errors(); | |
| 297 | 311 | |
| 298 | - $data_table = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}popularpostsdata'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 299 | - $summary_table = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}popularpostssummary'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 312 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared | |
| 313 | + if ( false === $wpdb->query( $query ) ) { | |
| 314 | + $tables_exist = false; | |
| 315 | + } | |
| 300 | 316 | |
| 301 | - if ( ! $data_table || ! $summary_table ) { | |
| 302 | - $tables_exist = false; | |
| 317 | + $wpdb->suppress_errors( $suppress_errors ); | |
| 303 | 318 | } |
| 319 | + | |
| 320 | + $cache[ $key ] = $tables_exist; | |
| 304 | 321 | |
| 305 | 322 | return $tables_exist; |
| 306 | 323 | } |
| 307 | 324 | |