From 207a5ef4b3c02ce6aee788876ecfed3c1ee4eb6b Mon Sep 17 00:00:00 2001 From: Gerhard Date: Thu, 28 Feb 2019 15:30:17 +0200 Subject: [PATCH 1/3] Add user_order_remaining_expires index to woocommerce_downloadable_product_permissions create table statement. --- includes/class-wc-install.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-install.php b/includes/class-wc-install.php index f1e2a970581..9234156b23a 100644 --- a/includes/class-wc-install.php +++ b/includes/class-wc-install.php @@ -692,7 +692,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, From b8a5a9ec5531019de9fe4522f4b1d0247a5d009d Mon Sep 17 00:00:00 2001 From: Gerhard Date: Thu, 28 Feb 2019 15:36:55 +0200 Subject: [PATCH 2/3] Add update routine to add user_order_remaining_expires index and hook it up to the installer for 3.6.0 --- includes/class-wc-install.php | 4 ++++ includes/wc-update-functions.php | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/includes/class-wc-install.php b/includes/class-wc-install.php index 9234156b23a..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', + ), ); /** diff --git a/includes/wc-update-functions.php b/includes/wc-update-functions.php index 469b21f2668..6800a9535e2 100644 --- a/includes/wc-update-functions.php +++ b/includes/wc-update-functions.php @@ -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' ); +} From 36f0041673e5dfd6e37820eed44de97ff7688ca4 Mon Sep 17 00:00:00 2001 From: Gerhard Date: Thu, 28 Feb 2019 15:37:37 +0200 Subject: [PATCH 3/3] PHPCS fixes --- includes/wc-update-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wc-update-functions.php b/includes/wc-update-functions.php index 6800a9535e2..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(),