1

I updated magento to the latest version 2.4.5, it will load all products on category page, but I have more than 60000 skus, it load very slow. how to limit pre-loading 10k skus likes old version? I tried to change search_request.xml file, but it's not working for me.

I always got error: FastCGI sent in stderr: "PHP message: PHP Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 20480 bytes) in /aaa/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php on line 292" while reading response header from upstream, client: 127.0.0.1, server: pazdb.com, request: "GET /en_laptop/replacement-laptop-screens.html HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/www.sock:", host: "www.aaa.com", referrer: "https://www.aaa.com/"

whatever I changed memory_limit=-1.

2 Answers 2

0

If you are experiencing slow loading times on your category page after updating Magento to version 2.4.5 and have a large number of SKUs, you can limit the number of pre-loaded SKUs to improve the page's loading speed. To do so, follow these steps:

  1. Create a custom module or use an existing one.

  2. In the module's di.xml file, add the following code:

     <type name="Magento\Catalog\Model\Config">
         <arguments>
             <argument name="pageSize" xsi:type="number">10000</argument>
         </arguments>
     </type>
    
  3. Replace 10000 with the desired number of SKUs to pre-load, such as 5000.

  4. Save the di.xml file and flush the Magento cache.

After following these steps, the category page will only pre-load the number of SKUs specified in the di.xml file. This should improve the page's loading speed, especially if you have a large number of SKUs.

1
  • Thank you for your help, I created di.xml in my custom module app/code/custom/default/etc/di.xml, re-deployed and reindexed, I also cleared all caches, but still loads all products.
    – myfixone
    Commented Mar 8, 2023 at 15:48
0

In new Magento version, the pager is build in the SearchCriteriaResolver

public function resolve(): SearchCriteria
{
    $searchCriteria = $this->builder->create();
    $searchCriteria->setRequestName($this->searchRequestName);
    $searchCriteria->setSortOrders($this->orders);
    $searchCriteria->setCurrentPage($this->currentPage - 1);
    if ($this->size) {
        $searchCriteria->setPageSize($this->size);
    }

    return $searchCriteria;
}

Change this function, the elasticsearch will return the total result which was configured in the search_request.xml

File: vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchCriteriaResolver.php:77

The new function look like this:

public function resolve(): SearchCriteria
{
    $searchCriteria = $this->builder->create();
    $searchCriteria->setRequestName($this->searchRequestName);
    $searchCriteria->setSortOrders($this->orders);
    $searchCriteria->setCurrentPage($this->currentPage - 1);
    return $searchCriteria;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.