Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 1.02 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Magento - fetching products and looping through is getting slower and slower
  2. $product = Mage::getModel('catalog/product');
  3. $data = $product->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('type_id', 'simple');
  4. $num_products = $product->getCollection()->count();
  5. echo 'exporting '.$num_products."n";
  6.  
  7. print "starting exportn";
  8. $start_time = time();
  9. foreach ($data as $tProduct) {
  10.     // doing some stuff, no sql !
  11. }
  12.        
  13. VIRT   RES   SHR S CPU% MEM%
  14.   680M  504M  8832 R 90.0  6.3
  15.        
  16. public function __construct(Zend_Db_Adapter_Abstract $adapter)
  17. {
  18.    parent::__construct($adapter);
  19.    if (!in_array(self::STRAIGHT_JOIN_ON, self::$_joinTypes)) {
  20.       self::$_joinTypes[] = self::STRAIGHT_JOIN_ON;
  21.       self::$_partsInit = array(self::STRAIGHT_JOIN => false) + self::$_partsInit;
  22.    }
  23. }
  24.        
  25. public function __construct(Zend_Db_Adapter_Abstract $adapter)
  26. {
  27.    parent::__construct($adapter);
  28.    self::$_joinTypes[] = self::STRAIGHT_JOIN_ON;
  29.    self::$_partsInit = array(self::STRAIGHT_JOIN => false) + self::$_partsInit;
  30. }