commerce icon indicating copy to clipboard operation
commerce copied to clipboard

[3.x]: Adding lots of shipping methods slows down fetching cart

Open joostwaaijer opened this issue 1 year ago • 0 comments

What happened?

Description

For a customer we've imported over 750+ shipping methods. After these shipping methods were imported (Even when disabled) the duration of fetching the cart takes significantly more time, so page loads are also slowed down massively, after deleting these shipping methods, the page speed returned to normal. The imported shipping methods only used the standard shipping methods / rules. Please not that we have the option autoSetCartShippingMethodOption turned on, this probably affects the performance.

Digging some deeper into the code, I see that getAllShippingMethods from the ShippingMethods service are actually fetching all shipping methods, including disabled ones, I think this could actually use filter on enabled, otherwise create a new getAllEnabledShippingMethods and use that for automatically setting the shipping method.

Steps to reproduce

  1. Turn on autoSetCartShippingMethodOption in craft settings
  2. Add 750+ shipping methods
  3. Fetch cart on pages

Expected behavior

Fetching cart should not be impacted by disabled shipping method options.

Actual behavior

Fetching cart is negatively impacted by disabled shipping method options.

Craft CMS version

Craft Pro 3.9.10

Craft Commerce version

3.4.23

PHP version

8.3.1

Operating system and version

No response

Database type and version

Postgresql

Image driver and version

No response

Installed plugins and versions

joostwaaijer avatar Jan 17 '24 12:01 joostwaaijer