Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug + fix: Site crashes with out of memory error when adding a downloadable product and hitting Update button #536

Open
1 task done
lordspace opened this issue Nov 4, 2023 · 0 comments
Labels
type: bug The issue is a confirmed bug.

Comments

@lordspace
Copy link

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

  • This affects WooCommerce Subscriptions? yes

Additional context

I made this fix.
https://gist.github.com/lordspace/f3c56d64fd6e22f7e1126d9fd0472257

@lordspace lordspace added the type: bug The issue is a confirmed bug. label Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug The issue is a confirmed bug.
Projects
None yet
Development

No branches or pull requests

1 participant