I have an external file containing product details, I'm looping through this file and for each product in said file I have to check if the product already exists in magento.
The value to evaluate if the product already exists is an attributename and it's value.
So I check this by using (per product)
$collection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('sku') ->addAttributeToSelect("$supplier_name") ->addAttributeToSelect('production_nr') ->addAttributeToSelect('sku_supplier') ->addAttributeToFilter($supplier_name,array('eq' => $suppliers_product_nr));
This selection itself doesn't seem to take much time:
echo 'check: ',round(microtime(true) - $time, 2) , "s<br/>\n";
reports 0.00 s,
however to check if it's an empty collection (ie the product exists in my magento database takes about 0.34-0.40 s
Considering I've got several hundred of thousands of products to check. This will add up quickly. Very quickly. I was hoping for something more akin to 0.01 or lower in time.
So I'm looking for the fastest way to check if a product exists. I have quite a bit of freedom in how to change and implement the code so if there's an completely different way of appreaching this problem I'd like to hear about it.
I've changed it slightly so that instead of checking with magento if a product exists product by product, I instead get an array of all products that have the attribute to check against. I use this array to check if the attribute to check against exists.
This is way faster, but I fear for the overhead impact (primarily ram or cpu) this will have once the amount of products returned becomes too great (we've got about 40.000 products in our magento installation)