I'm trying to execute some backend logic via ajax that requires using the Magento\Sales\Model\ResourceModel\Order\Item\CollectionFactory collection factory.

When I use ->getColumnValues('<some column>'), I run out of memory if I don't set the php memory limit at 2GB. Most importantly, the memory doesn't clean itself out after code execution.

Before execution: enter image description here

During execution: enter image description here

After execution: enter image description here

The controller in question:


namespace ...

use Magento\Sales\Model\ResourceModel\Order\Item\CollectionFactory as OrderItemCollectionFactory;

class Statistics extends Action
    public function __construct(
        OrderItemCollectionFactory $orderItemCollectionFactory,
        $this->_orderItemCollectionFactory = $orderItemCollectionFactory;

    public function execute()
        $product_ids = $this->getBrandProductIds();
        $json = $this->_jsonFactory->create();
        return $json->setData([
            'test' => $this->_orderItemCollectionFactory->create()
                ->addFieldToFilter('product_id', ['in' => $product_ids])
  • Did you try printing the data before setting it into json to see if it contains the only data you require and not extra data. – Abdul Samad Abbasi Nov 9 '20 at 11:27
  • @AbdulSamadAbbasi After further investigation, even the ->count() method, which I need later on, overflows the memory – Badong Nov 9 '20 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.