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.
The controller in question:
<?php
namespace ...
use Magento\Sales\Model\ResourceModel\Order\Item\CollectionFactory as OrderItemCollectionFactory;
class Statistics extends Action
{
public function __construct(
...
OrderItemCollectionFactory $orderItemCollectionFactory,
...
)
{
parent::__construct($context);
...
$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])
->getColumnValues('order_id')
]);
}
}
->count()
method, which I need later on, overflows the memory