commerce icon indicating copy to clipboard operation
commerce copied to clipboard

Eager loading Order Notices can cause memory issues

Open CharlieGentle opened this issue 4 years ago • 1 comments

Description

We have a cart that belongs to an admin user and has persisted for a while. It has somehow accumulated a huge amount of order notices (over 16000) and this is causing issues across the site. Because of the eager loading of the order notices on order queries, we are experiencing memory limit issues whenever this cart is returned in a query.

I'm not sure how so many order notices have accumulated and if this has happened to any other carts but it would be good to have the option to not eager load the order notices. If there was a good solution to stop the Order Notices reaching that kind of number, that would also be good.

image

Steps to reproduce

  1. Create orders with a lot of Order Notices (not sure how)
  2. Run order query that contains these orders.

Additional info

  • Craft CMS version: 3.6.15
  • Craft Commerce version: 3.3.2
  • PHP version: 7.3.30
  • Database driver & version: MySQL 5.5.5
  • Plugins & versions:

CharlieGentle avatar Jan 25 '22 17:01 CharlieGentle

Hi @pdaleramirez, is there an update on this? We're experiencing a similar issue with one of our sites. The site uses a custom plugin to set the price of a product based on the qty ordered (e.g. qty:1 = £10, qty:3 = £9.50, qty:6 = £9.25). This causes a "lineItemSalePriceChanged" order notice to be created.

For some reason there are a few orders that have thousands of order notices (one order has over 33,000) - checking in the database, it looks like hundreds of notices are created at the same time as they all have the same dateCreated timestamp.

It would be good to have either an event that we can use to prevent order notices being created or a config setting where we can select to disabled order notices.

mcjackson18 avatar Mar 31 '22 09:03 mcjackson18

You can use the EVENT_BEFORE_APPLY_ADD_NOTICE or EVENT_BEFORE_ADD_NOTICE events to stop a notice from being added or saved.

lukeholder avatar Dec 06 '22 02:12 lukeholder