Merge pull request #22906 from woocommerce/add/downloadable_product_permissions_index

get_downloads_for_customer performance improvement via index
This commit is contained in:
Mike Jolley 2019-03-04 14:15:11 +00:00 committed by GitHub
commit f18f4082b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -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,

View File

@ -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' );
}