Check if there is a comment_type index before adding one
Adding this check to avoid a MySQL error when running the query if the index already exists.
This commit is contained in:
parent
2e8f02f6a4
commit
7acf712e45
|
@ -404,10 +404,14 @@ class WC_Install {
|
|||
|
||||
dbDelta( self::get_schema() );
|
||||
|
||||
$index_exists = $wpdb->get_row( "SHOW INDEX FROM {$wpdb->comments} WHERE Column_name = 'comment_type' and Key_name = 'comment_type'" );
|
||||
|
||||
if ( is_null( $index_exists ) ) {
|
||||
// Add an index to the field comment_type to improve the response time of the query
|
||||
// used by WC_Comments::wp_count_comments() to get the number of comments by type.
|
||||
$wpdb->query( "ALTER TABLE {$wpdb->comments} ADD INDEX woo_idx_comment_type (comment_type)" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Table schema.
|
||||
|
|
Loading…
Reference in New Issue