Magento 2.3的速度非常慢,超过100条购物车行

时间:2019-07-11 21:40:48

标签: php magento magento2

我正在使用Magento 2.3安装,平均购物车大小为100-150行。 随着时间的流逝,随着报价的增长,从“报价”中获取可见的购物车商品会变慢。

我搜索过Magento核心,发现延迟是因为它试图从数据库中获取报价(?)

$ quote = $ this-> quoteRepository-> getActive($ this-> getQuoteId());

public function getQuote()
{
    $this->_eventManager->dispatch('custom_quote_process', ['checkout_session' => $this]);

    if ($this->_quote === null) {
        $quote = $this->quoteFactory->create();
        if ($this->getQuoteId()) {
            try {
                if ($this->_loadInactive) {
                    $quote = $this->quoteRepository->get($this->getQuoteId());
                } else {
                    $quote = $this->quoteRepository->getActive($this->getQuoteId());
                }

                /**
                 * If current currency code of quote is not equal current currency code of store,
                 * need recalculate totals of quote. It is possible if customer use currency switcher or
                 * store switcher.
                 */
                if ($quote->getQuoteCurrencyCode() != $this->_storeManager->getStore()->getCurrentCurrencyCode()) {
                    $quote->setStore($this->_storeManager->getStore());
                    $this->quoteRepository->save($quote->collectTotals());
                    /*
                     * We mast to create new quote object, because collectTotals()
                     * can to create links with other objects.
                     */
                    $quote = $this->quoteRepository->get($this->getQuoteId());
                }
            } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
                $this->setQuoteId(null);
            }
        }

        if (!$this->getQuoteId()) {
            if ($this->_customerSession->isLoggedIn() || $this->_customer) {
                $customerId = $this->_customer
                    ? $this->_customer->getId()
                    : $this->_customerSession->getCustomerId();
                try {
                    $quote = $this->quoteRepository->getActiveForCustomer($customerId);
                    $this->setQuoteId($quote->getId());
                } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
                }
            } else {
                $quote->setIsCheckoutCart(true);
                $this->_eventManager->dispatch('checkout_quote_init', ['quote' => $quote]);
            }
        }

        if ($this->_customer) {
            $quote->setCustomer($this->_customer);
        } elseif ($this->_customerSession->isLoggedIn()) {
            $quote->setCustomer($this->customerRepository->getById($this->_customerSession->getCustomerId()));
        }

        $quote->setStore($this->_storeManager->getStore());
        $this->_quote = $quote;
    }

    if (!$this->isQuoteMasked() && !$this->_customerSession->isLoggedIn() && $this->getQuoteId()) {
        $quoteId = $this->getQuoteId();
        /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */
        $quoteIdMask = $this->quoteIdMaskFactory->create()->load($quoteId, 'quote_id');
        if ($quoteIdMask->getMaskedId() === null) {
            $quoteIdMask->setQuoteId($quoteId)->save();
        }
        $this->setIsQuoteMasked(true);
    }

    $remoteAddress = $this->_remoteAddress->getRemoteAddress();
    if ($remoteAddress) {
        $this->_quote->setRemoteIp($remoteAddress);
        $xForwardIp = $this->request->getServer('HTTP_X_FORWARDED_FOR');
        $this->_quote->setXForwardedFor($xForwardIp);
    }

    return $this->_quote;
}

平均延迟大约15到25秒。有没有办法将这种数据存储在像Redis这样的缓存存储中?我已经将Redis设置为没有运气的存储缓存。

还有其他人遇到这种问题吗? Magento Changelog声称载有大约300行的购物车应该没问题

https://devdocs.magento.com/guides/v2.2/release-notes/ReleaseNotes2.2.0CE.html

该项目在具有32gb RAM和8核XEON Cpu的专用服务器上运行

更新

经过更多调查后,我发现延迟发生在Quote.php行1380-1391上

public function getItemsCollection($useCache = false)
{
    if ($this->hasItemsCollection()) {
        return $this->getData('items_collection');
    }
    if (null === $this->_items) {
        $this->_items = $this->_quoteItemCollectionFactory->create();
        $this->extensionAttributesJoinProcessor->process($this->_items);
        $this->_items->setQuote($this);
    }
    return $this->_items;
}

奇怪的是,在请求此收集时,Redis CLI监视器上没有任何流量,这种数据不应该存储在Redis中吗?

更新2

在getItemsCollection函数周围似乎有一个“插件”或其他东西。我已经停止执行它,并且响应是立即的,如果我让它返回$ this-> items显示了延迟。试图使用xdebug来查找导致延迟的原因,但是没有运气。 Xdebug跟随执行,直到Collection.php丢失了。 Mysql探查器显示了购物车页面中正在运行的大约1500个查询(我认为这是一个很大的数目),尽管它们都没有持续超过5毫秒(大约15毫秒左右)的时间。

因此,我安装了一个带有luna主题的全新magento装置,并使用composer导入了示例产品。 新的虚拟机具有MySql 5.7,PHP-FPM 7.2和redis。 启用生产模式,除page_cache之外的所有高速缓存,并将默认高速缓存设置为redis 在购物车中添加了46件商品,仅文档加载的结果就是〜13s

enter image description here

我不能接受Magento无法处理这种大小的购物车。最终用户不能接受这段时间。

没有从哪里开始搜索的线索。

0 个答案:

没有答案