checkout / checkout-magento2-plugin

Checkout.com Magento 2 official extension
MIT License
32 stars 32 forks source link

Performance issue on checkout page. #516

Open kpitn opened 1 year ago

kpitn commented 1 year ago

Hi,

I'm using the last version module (4.1.1)

Instead of using order collection, repository is use with searchcriteria.

File : /vendor/checkoutcom/magento2/Model/Service/OrderHandlerService.php

        /** @var OrderInterface $order */
        $order = $this->orderRepository->getList($search)->setPageSize(1)->getLastItem();

Magento getlist load all customer orders before limiting the query with last item.

screen

items

kpitn commented 1 year ago

Patch to solve the problem (if you want to keep repository)

--- Model/Service/OrderHandlerService.php
+++ Model/Service/OrderHandlerService.php
@@ -289,10 +289,16 @@

         // Create the search instance
         $search = $this->searchBuilder->create();
+        /** @var SortOrder $sortOrder */
+        $sortOrder = \Magento\Framework\App\ObjectManager::getInstance()->create(\Magento\Framework\Api\SortOrderBuilder::class)
+            ->setField('created_at')
+            ->setDirection(\Magento\Framework\Api\SortOrder::SORT_ASC)
+            ->create();
+        $search->setPageSize(1)->setSortOrders([$sortOrder]);

         // Get the resulting order
         /** @var OrderInterface $order */
-        $order = $this->orderRepository->getList($search)->setPageSize(1)->getLastItem();
+        $order = $this->orderRepository->getList($search)->getLastItem();

         if ($order->getId()) {
             $this->logger->additional($this->getOrderDetails($order), 'order');
Dnd-Gimix commented 1 year ago

Hello @kpitn ,

Thanks a lot for the feedback, very efficient as always! ;) This is taken into account and we will work on it in the near future.

We will keep you posted of our progress regarding this improvement.

Regards,

JamesFX2 commented 1 year ago

I flagged the same in https://github.com/checkout/checkout-magento2-plugin/pull/503 but sadly, this was missed.

I'm undecided if I should continue to raise issues with this project.

Off the top of my head, there are

They've released versions that have broken filters (so crashed the checkout loading 2 million transactions to try and figure out the last payment method used), have put PHP 8.0 specific code in versions meant for 7.x, had invalid JS that broke checkouts.

Every time, it's an ordeal that ends up becoming a game of message passing between the internal support team and their Magento agency. I have 18 separate plugins, 8 class rewrites fixing or altering things on your extension. It's my preferred solution these days. It saves my time jumping through hoops to help a company that's valued at $40 billion.