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

Collection performance outside of cart very slow #2419

Open
cboelter opened this issue Feb 15, 2023 · 1 comment
Open

Collection performance outside of cart very slow #2419

cboelter opened this issue Feb 15, 2023 · 1 comment

Comments

@cboelter
Copy link
Contributor

A customer created a bigger cart with 84 products inside the cart. In the card module the list was rendered fast as expected. Inside the checkout process the whole checkout slowed down. After checking the code a bit it seems that the Standard::getPrice() function is called a lot of times.
Inside the cart the function is called the same amount as in the checkout process (10 Products are producing 248 calls of the Standard::getPrice() function).
I think the problem is that in the cart the price is only fetched once from the database and in all other collections the price is fetched everytime the Standard::getPrice() function is called.
I would suggest to cache also the other prices of collections inside the product object. For testing I created something like this:

public function getPrice(IsotopeProductCollection $objCollection = null)
    {
        if (null !== $objCollection && $objCollection !== Isotope::getCart()) {
            if(!$this->collectionPrices[$objCollection->id]) {
                $this->collectionPrices[$objCollection->id] = ProductPrice::findByProductAndCollection($this, $objCollection);
            }

            return $this->collectionPrices[$objCollection->id];
        }

        if (false === $this->objPrice) {
            if (null === $objCollection) {
                $objCollection = Isotope::getCart();
            }

            $this->objPrice = ProductPrice::findByProductAndCollection($this, $objCollection);
        }

        return $this->objPrice;
    }

If you are fine with this, I could create a PR for this.

@aschempp
Copy link
Member

if I remember correctly there were reasons not to cache the price, mostly because the checkout process can affect it. That's gonna be difficult to debug, but if you could come up with a draft that would be great! 😊

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

2 participants