You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Site crashes with out of memory error when adding a downloadable product and hitting Update button
This happens with the latest version of the Woo Subscriptions which is v5.6.0
To Reproduce
You need one subscription product with 100s of downloadable products and lots of orders.
wp db query --debug 'SELECT count(download_id) from some_prefix_woocommerce_downloadable_product_permissions WHERE product_id = 20901'
SELECT order_id, download_id from some_prefix_woocommerce_downloadable_product_permissions WHERE product_id = 20901
This function is the cause of the error as it puts everything in the memory.
The function returned 2+ million rows.
grant_new_file_product_permissions( $product_id, $variation_id, $downloadable_files )
Describe the bug
Site crashes with out of memory error when adding a downloadable product and hitting Update button
This happens with the latest version of the Woo Subscriptions which is v5.6.0
To Reproduce
You need one subscription product with 100s of downloadable products and lots of orders.
wp db query --debug 'SELECT count(download_id) from some_prefix_woocommerce_downloadable_product_permissions WHERE product_id = 20901'
SELECT order_id, download_id from some_prefix_woocommerce_downloadable_product_permissions WHERE product_id = 20901
+--------------------+
| count(download_id) |
+--------------------+
| 2319695 |
+--------------------+
Expected behavior
Not to crash due to memory limits.
Actual behavior
This function is the cause of the error as it puts everything in the memory.
The function returned 2+ million rows.
grant_new_file_product_permissions( $product_id, $variation_id, $downloadable_files )
/Automattic/woocommerce-subscriptions-core/blob/trunk/includes/class-wcs-download-handler.php#L232C25-L232C59
](https://github.com/Automattic/woocommerce-subscriptions-core/blob/trunk/includes/class-wcs-download-handler.php#L232C25-L232C59)
$existing_permissions = $wpdb->get_results( $wpdb->prepare( "SELECT order_id, download_id from {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE product_id = %d", $product_id ) );
Product impact
Additional context
I made this fix.
https://gist.github.com/lordspace/f3c56d64fd6e22f7e1126d9fd0472257
The text was updated successfully, but these errors were encountered: