Performance Issue and possible solution
-
Hello,
We found out using Query Monitor that your plugin is doing multiple SHOW TABLE queries and unfortunately it affects the performance on our sites by a lot.
Proof: https://prntscr.com/pj03qj
I modified the function for you to implement in-memory object cache using wp_cache.* native WordPress functions to implement object cache and prevent multiple SQL queries during the page load:
/** * Default Settings * @since 1.8 * @version 1.0 */ public function get_log_table() { global $wpdb; if ( $this->is_multisite && $this->use_central_logging ) $wp_prefix = $wpdb->base_prefix; else $wp_prefix = $wpdb->prefix; // Custom: Use object cache here $table_name = wp_cache_get('mycred_log_table_name'); if( FALSE === $table_name ) { $table_name = $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $wp_prefix . 'myCRED_log' ) ); if( $table_name !== NULL ) { wp_cache_set('mycred_log_table_name', $table_name); } } if( $table_name == NULL ) { $table_name = $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $wp_prefix . 'mycred_log' ) ); if( $table_name == NULL ) { $table_name = $wp_prefix . 'myCRED_log'; } // Custom: Use object cache here wp_cache_set('mycred_log_table_name', $table_name); } if ( defined( 'MYCRED_LOG_TABLE' ) ) $table_name = MYCRED_LOG_TABLE; return $table_name; }
Please feel free to test and update the plugin. This will be beneficial to many other users striving for performance.
Best,
Darko G
- The topic ‘Performance Issue and possible solution’ is closed to new replies.