Merge pull request #7475 from woothemes/improve-get-downloads-speed

Improve wc_get_customer_available_downloads speed
This commit is contained in:
Mike Jolley 2015-02-18 11:12:19 +00:00
commit 697ece3b3c
1 changed files with 5 additions and 2 deletions

View File

@ -388,10 +388,8 @@ function wc_get_customer_available_downloads( $customer_id ) {
$results = $wpdb->get_results( $wpdb->prepare( " $results = $wpdb->get_results( $wpdb->prepare( "
SELECT permissions.* SELECT permissions.*
FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions as permissions FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions as permissions
LEFT JOIN {$wpdb->posts} as posts ON permissions.order_id = posts.ID
WHERE user_id = %d WHERE user_id = %d
AND permissions.order_id > 0 AND permissions.order_id > 0
AND posts.post_status IN ( '" . implode( "','", array_keys( wc_get_order_statuses() ) ) . "' )
AND AND
( (
permissions.downloads_remaining > 0 permissions.downloads_remaining > 0
@ -416,6 +414,11 @@ function wc_get_customer_available_downloads( $customer_id ) {
$_product = null; $_product = null;
} }
// Make sure the order exists for this download
if ( ! $order ) {
continue;
}
// Downloads permitted? // Downloads permitted?
if ( ! $order->is_download_permitted() ) { if ( ! $order->is_download_permitted() ) {
continue; continue;