From 611768c9cd492bb94885f3ec850a9c5c5f568ae6 Mon Sep 17 00:00:00 2001 From: Marc Harding Date: Wed, 23 Sep 2015 22:10:10 +0200 Subject: [PATCH] Faster image and deeplink export This improves speed when images and deeplinks are exported. In my test cases the export now takes about 50% less time and uses 10% less memory than before (ymmv). --- .../FactFinder/Model/Export/Product.php | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/app/code/community/Flagbit/FactFinder/Model/Export/Product.php b/src/app/code/community/Flagbit/FactFinder/Model/Export/Product.php index 6e2f38e4..4140026d 100644 --- a/src/app/code/community/Flagbit/FactFinder/Model/Export/Product.php +++ b/src/app/code/community/Flagbit/FactFinder/Model/Export/Product.php @@ -232,13 +232,28 @@ public function doExport($storeId = null) ); if ($exportImageAndDeeplink) { - $product = Mage::getModel("catalog/product"); - $product->setStoreId($storeId); - $product->load($productData['entity_id']); - - $productIndex[] = (string) $this->_imageHelper->init($product, $imageType)->resize($imageSize); - $productIndex[] = $product->getProductUrl(); - $product->clearInstance(); + list($width, $height) = explode('x', strtolower($imageSize)); + $imageBaseFile = Mage::getResourceSingleton('catalog/product')->getAttributeRawValue($productData['entity_id'], $imageType, $storeId); + $imageModel = Mage::getModel('catalog/product_image') + ->setWidth($width) + ->setHeight($height) + ->setDestinationSubdir($imageType) + ->setBaseFile($imageBaseFile); + if(!$imageModel->isCached()) { + $imageModel->resize(); + } + $productImage = $imageModel->getUrl(); + + $productUrl = Mage::getModel('catalog/product') + ->getCollection() + ->addAttributeToFilter('entity_id', $productData['entity_id']) + ->setStoreId($storeId) + ->addUrlRewrite() + ->getFirstItem() + ->getProductUrl(); + + $productIndex[] = $productImage; + $productIndex[] = $productUrl; } $this->_getAttributesRowArray($productIndex, $productAttr, $storeId);