Skip to content

[5.x]: Inventory::getInventoryFulfillmentLevels() causing slowdowns on cart updates. #4056

@joshuapease

Description

@joshuapease

Description

We've noticed some really big slowdowns around inventory and cart updates.

LineItem::getFulfilledTotalQuantity() which subsequently calls Inventory::getInventoryFulfillmentLevels() calls the same query to commerce_inventorytransactions for each line item.

This project has 600,000+ skus, which makes this query especially slow.

We also don't track inventory on this project, so it seems like their might be some efficiency gains if the query could just be skipped for purchasables that don't have $inventoryTracked = true

Image

Image

I noticed this PR was opened recently too

Steps to reproduce

  1. Have a high number of Variants in Craft (600,000+)
  2. Add multiple items to cart

Expected behavior

  • Only one call to Inventory::getInventoryFulfillmentLevels()
  • Ideally this query is bypassed when a purchasable doesn't track inventory.

Actual behavior

  • Calls to Inventory::getInventoryFulfillmentLevels() grow as line items increase

Craft CMS version

5.7.4

Craft Commerce version

5.3.13

PHP version

8.3

Operating system and version

DDEV

Database type and version

8.0.40

Image driver and version

No response

Installed plugins and versions

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions