strangerstudios / sitewide-sales

Run Black Friday, Cyber Monday, or other flash sales on your WordPress-powered eCommerce or membership site with WooCommerce, Easy Digital Downloads, and Paid Memberships Pro.
https://sitewidesales.com
GNU General Public License v3.0
3 stars 6 forks source link

Memory issue on sites with many coupons. #138

Closed ideadude closed 1 year ago

ideadude commented 1 year ago

Describe the bug

Ran into an issue on a WooCommerce site that had 33,000+ coupons. The new sale page would fail with an out of memory issue. Looking into it, it seemed to be due to the query to get the coupons for the WC dropdown.

To Reproduce Steps to reproduce the behavior:

  1. Somehow put 33k coupons in your site.
  2. Use less than 500mb RAM for your admin user.
  3. Try to create a coupon.
  4. Choose WC from the dropdown.

Notice none of the other fields are loading... because the page should fatal error out.

Suggestions

We should perhaps do a custom query here that just gets the coupon code and ID from the posts table, since (I think) those are the only values we need.

Alternatively, updating the args here to include a few performance-related ones helps: https://github.com/strangerstudios/sitewide-sales/blob/dev/modules/ecommerce/wc/class-swsales-module-wc.php#L88-L94

$args = array(
    'posts_per_page'   => -1,
    'orderby'          => 'title',
    'order'            => 'asc',
    'post_type'        => 'shop_coupon',
    'post_status'      => 'publish',
    //new args below here:
    'nopaging' => true,
    'no_found_rows' => true,
    'update_post_meta_cache' => false,
    'update_post_term_cache' => false
);

Related Stack Overflow: https://wordpress.stackexchange.com/questions/98102/is-there-a-way-to-exclude-the-content-from-the-post-variable-to-save-on-ram-usag

Isolating the problem (mark completed items with an [x]):

mircobabini commented 1 year ago

Advanced docs:

kimcoleman commented 1 year ago

The updates in the PR attached to this issue have been pushed to a site that was experiencing the issue and its still not working very swiftly. What alternatives can we consider?