Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taxjar extension performance issues #378

Open
11 tasks done
snoop0x7b opened this issue Nov 20, 2024 · 0 comments
Open
11 tasks done

Taxjar extension performance issues #378

snoop0x7b opened this issue Nov 20, 2024 · 0 comments

Comments

@snoop0x7b
Copy link

Prerequisites

Description

This extension causes performance issues in checkout and in cart editing operations because it uses a query-in-a-loop anti-pattern. Secondly, to make matters worse, it also uses the product repository for its fetch operations, fetching unnecessary product attributes, which makes these queries slower.

Model/Tax/Sales/Total/Quote/Tax.php:352-366

        try {
            $product = $this->productRepository->getById($item->getProductId(), false, $item->getStoreId());
            
            // Configurable products should use the PTC of the child (when available)
            if ($product->getTypeId() == 'configurable') {
                $children = $item->getChildren();
        
                if (is_array($children) && isset($children[0])) {
                    $product = $this->productRepository->getById(
                        $children[0]->getProductId(),
                        false,
                        $item->getStoreId()
                    );
                }
            }
                
            $extensionAttributes->setTjPtc($product->getTjPtc());
        } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
            $msg = $e->getMessage() . "\nline item" . $itemDataObject->getCode() . ' for ' . $item->getRowTotal();
            $this->logger->log($msg); 
        } 

This method is called once per product in the cart.

This should be refactored to use the product collection, and be built into the caller, so that this isn't called once per product.

Steps to Reproduce

  1. Build a cart of a 5+ items on a store with a large number of attributes (50+)
  2. Connect a PHP profiling or debugger
  3. Remove items from the cart - Item removal will be slow.

Expected Result

Cart editing should run in O(1) time because we shouldn't be executing queries for every item in the cart, or fetching every single attribute.

Actual Result

Editing the cart is slow. Progressing through checkout steps is slow.

Versions

  • Magento 2.4
  • Magento 2.3
  • Magento Open Source (fka Magento 2 Community Edition)
  • Adobe Commerce (fka Magento 2 Enterprise Edition)
  • PHP 8.2
  • PHP 8.1
  • PHP 7.4
  • PHP 7.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant