• Hello,

    We have a customer with a large multisite (555 blogs), so they have 19,614 tables in WP database. Regularly we notice high CPU usage on DB server with a large amount of queries like SHOW TABLES LIKE ?. I was able to find out the query initiates from wpml_reload_active_languages_setting() function, when it verifies the table exists with $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}icl_languages'":

    I propose a better way to make sure the table exists without querying all tables, see below:

    # File: wp-content/plugins/sitepress-multilingual-cms/inc/functions-load.php
    # Line 212
    
    205 function wpml_reload_active_languages_setting( $override = false ) {
    206         global $wpdb, $sitepress_settings;
    207         global $wpdb, $sitepress_settings;
    208 
    209         if ( true === (bool) $sitepress_settings
    210                  && ( $override || wpml_is_setup_complete() )
    211         ) {
    212                 //if ( $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}icl_languages'" ) ) {
                        if ( $wpdb->query( "SELECT 1 FROM {$wpdb->prefix}icl_languages LIMIT 1" ) ) {
    213                         $active_languages = $wpdb->get_col(
    214                                 "       SELECT code
    215                                                                                                                                         FROM {$wpdb->prefix}icl_languages
    216                                                                                                                                         WHERE active = 1"
    217                         );
    218                 } else {
    219                         $active_languages = array();
    220                 }
    221                 $sitepress_settings['active_languages'] = $active_languages;
    222                 icl_set_setting( 'active_languages', $active_languages, true );
    223         } else {
    224                 $active_languages = array();
    225         }
    226 
    227         return (array) $active_languages;
    228 }<code></code>
    
    Additional info:
    
    

    | name | sitepress-multilingual-cms |
    | title | WPML Multilingual CMS |
    | author | OnTheGoSystems |
    | version | 4.4.10

    Wordpress version 5.7.2`


    Thanks

  • The topic ‘SHOW TABLES LIKE {$wpdb->prefix}icl_languages’ is closed to new replies.