Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Why is my script exceeding the memory limit?

Why is my script exceeding the memory limit?

RSSMFG
Visitor
1 0 0

Message: Your script exceeded the memory limit.

Help with this please. I am not sure what the problem is. Thanks!

Screenshot 2023-11-28 at 10.09.37 AM.jpg

Replies 7 (7)

alyssa_tinytags
Shopify Partner
1 0 1

We are getting this same error on one of our scripts and I'm not sure what the problem is. 

prettypetty
Shopify Partner
11 0 1

Experiencing the same. Running the same script we did before BFCM (which had no errors) - seeing this memory error now but when I try to debug, none of the production errors show. 

Shopify partner since 2017
Liquid lover

Kostas_McDade
Shopify Partner
2 0 0

Seeing the same thing for the last 24 hours. Crazy spike. But conversion rates are holding just fine. 

jeremiahscanlon
Shopify Partner
5 0 1

If I'm reading this code correctly, you are looping through all the items in the cart three times. I recommend refactoring this code to make one loop and handle the conditionals inside the loop.

 

I did my best to type out how you could refactor this, but since your example is an image instead of text, please check for typos or syntax issues before replacing your existing code.

Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card?
if!Input.cart.customer.nil?
if Input.cart.customer.tags.include?('Wholesale')
line_item.change_line_price(line_item.line_price * 0.42, message: "Wholesale")
end
if Input.cart.customer.tags.include?('Non-Showroom Wholesale')
line_item.change_line_price(line_item.line_price * 0.42, message: "Wholesale Discount")
end
if Input.cart.customer.tags.include?('MAP')
line_item.change_line_price(line_item.line_price * 0.42, message: "MAP Discount")
end
end
end

 

Jonas10
Shopify Partner
10 0 5

Hi, we've been having the same issue. Also, seeing the message "unable to debug because the cart was too large" when hovering over the exclamation sign. Has anyone figured this out?
By the way we've completely re-written the script with the same outcome. 

Jonas10_0-1708345199424.png

 

Jonas10
Shopify Partner
10 0 5

Shopify's Partner Support responded this:

The "MemoryQuotaExceeded" error is not script code related 
It is caused by bots trying to checkout.
Something we cannot stop from our end, but you can by either upgrading your checkout or adding a bot blocker.
When you upgrade to Checkout Extensibility on Shopify, you enable a feature that enhances bot protection in your Checkout settings. This means that the system can identify and block known bots that may be attempting to make automated purchases on your website.
By slowing down bot activity, the feature creates a more level playing field for genuine customers, increasing their chances of successfully completing purchases without interference from malicious bots.
But, if you are to upgrade to extensibility, your scripts will no longer be available.

 And they confirmed it was safe to ignore it.

garyrgilbert
Shopify Partner
431 41 186

Thats not quite true, Script Editor is being sunset first next year so they will continue to function after the checkout has been upgraded.  I first started noticing this error after we upgraded the checkout, prior to that we had no issues with the script.

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution