diff --git a/includes/class-wc-install.php b/includes/class-wc-install.php index f1e2a970581..e84ccc051ad 100644 --- a/includes/class-wc-install.php +++ b/includes/class-wc-install.php @@ -124,6 +124,10 @@ class WC_Install { 'wc_update_354_modify_shop_manager_caps', 'wc_update_354_db_version', ), + '3.6.0' => array( + 'wc_update_360_downloadable_product_permissions_index', + 'wc_update_360_db_version', + ), ); /** @@ -692,7 +696,8 @@ CREATE TABLE {$wpdb->prefix}woocommerce_downloadable_product_permissions ( PRIMARY KEY (permission_id), KEY download_order_key_product (product_id,order_id,order_key(16),download_id), KEY download_order_product (download_id,order_id,product_id), - KEY order_id (order_id) + KEY order_id (order_id), + KEY user_order_remaining_expires (user_id,order_id,downloads_remaining,access_expires) ) $collate; CREATE TABLE {$wpdb->prefix}woocommerce_order_items ( order_item_id BIGINT UNSIGNED NOT NULL auto_increment, diff --git a/includes/wc-update-functions.php b/includes/wc-update-functions.php index 469b21f2668..affe3f71a27 100644 --- a/includes/wc-update-functions.php +++ b/includes/wc-update-functions.php @@ -740,7 +740,7 @@ function wc_update_240_shipping_methods() { if ( version_compare( $shipping_method->get_option( 'version', 0 ), '2.4.0', '<' ) ) { $shipping_classes = WC()->shipping()->get_shipping_classes(); $has_classes = count( $shipping_classes ) > 0; - $cost_key = $has_classes ? 'no_class_cost': 'cost'; + $cost_key = $has_classes ? 'no_class_cost' : 'cost'; $min_fee = $shipping_method->get_option( 'minimum_fee' ); $math_cost_strings = array( 'cost' => array(), @@ -1932,3 +1932,25 @@ function wc_update_354_modify_shop_manager_caps() { function wc_update_354_db_version() { WC_Install::update_db_version( '3.5.4' ); } + +/** + * Add new user_order_remaining_expires to speed up user download permission fetching. + * + * @return void + */ +function wc_update_360_downloadable_product_permissions_index() { + global $wpdb; + + $index_exists = $wpdb->get_row( "SHOW INDEX FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE key_name = 'user_order_remaining_expires'" ); + + if ( is_null( $index_exists ) ) { + $wpdb->query( "ALTER TABLE {$wpdb->prefix}woocommerce_downloadable_product_permissions ADD INDEX user_order_remaining_expires (user_id,order_id,downloads_remaining,access_expires)" ); + } +} + +/** + * Update DB Version. + */ +function wc_update_360_db_version() { + WC_Install::update_db_version( '3.6.0' ); +}