Post Made Community Wiki by sv3n
3 deleted 224 characters in body
source | link

GetFirstItem

getFirstItem() does not limit the result of collection load to one item.

incorrect:

$collection = Mage::getModel('catalog/category')
    ->load(41)
    ->getProductCollection()
    ->addAttributeToSelect('weight');

$product = $collection->getFirstItem();
$weight  = $product->getData('weight');

correct:

Apply limit before grab data.

$collection->getSelect()->limit(1)

or

$collection->setPageSize(1, 1)

Expamples:

Collection with 750 product:products ...

$collection = Mage::getModel('catalog/category')
    ->load(41)
    ->getProductCollection()
    ->addAttributeToSelect('weight');
$product = $collection->getFirstItem();
$weight  = $product->getData('weight');

Without limiting before:

  • Total Incl. Wall Time (microsec): 2,116,522 microsecs
  • Total Incl. CPU (microsecs): 2,101,688 microsecs
  • Total Incl. MemUse (bytes): 4,783,504 bytes
  • Total Incl. PeakMemUse (bytes): 4,363,112 bytes
  • Number of Function Calls: 104,187

With using getSelect()->limit(1):

  • Total Incl. Wall Time (microsec): 149,803 microsecs
  • Total Incl. CPU (microsecs): 131,405 microsecs
  • Total Incl. MemUse (bytes): 2,384,840 bytes
  • Total Incl. PeakMemUse (bytes): 1,827,112 bytes
  • Number of Function Calls: 5,327

With using setPageSize(1, 1)

  • Total Incl. Wall Time (microsec): 155,025 microsecs
  • Total Incl. CPU (microsecs): 136,191 microsecs
  • Total Incl. MemUse (bytes): 2,413,128 bytes
  • Total Incl. PeakMemUse (bytes): 1,856,064 bytes
  • Number of Function Calls: 5,515

Note:

This warning will still pop up, even if you limit your collection before. To get rid of this message use $collection->getLastItem() instead.

GetFirstItem

getFirstItem() does not limit the result of collection load to one item.

incorrect:

$collection = Mage::getModel('catalog/category')
    ->load(41)
    ->getProductCollection()
    ->addAttributeToSelect('weight');

$product = $collection->getFirstItem();
$weight  = $product->getData('weight');

correct:

Apply limit before grab data.

$collection->getSelect()->limit(1)

or

$collection->setPageSize(1, 1)

Expamples:

Collection with 750 product:

$collection = Mage::getModel('catalog/category')
    ->load(41)
    ->getProductCollection()
    ->addAttributeToSelect('weight');
$product = $collection->getFirstItem();
$weight  = $product->getData('weight');

Without limiting before:

  • Total Incl. Wall Time (microsec): 2,116,522 microsecs
  • Total Incl. CPU (microsecs): 2,101,688 microsecs
  • Total Incl. MemUse (bytes): 4,783,504 bytes
  • Total Incl. PeakMemUse (bytes): 4,363,112 bytes
  • Number of Function Calls: 104,187

With using getSelect()->limit(1):

  • Total Incl. Wall Time (microsec): 149,803 microsecs
  • Total Incl. CPU (microsecs): 131,405 microsecs
  • Total Incl. MemUse (bytes): 2,384,840 bytes
  • Total Incl. PeakMemUse (bytes): 1,827,112 bytes
  • Number of Function Calls: 5,327

With using setPageSize(1, 1)

  • Total Incl. Wall Time (microsec): 155,025 microsecs
  • Total Incl. CPU (microsecs): 136,191 microsecs
  • Total Incl. MemUse (bytes): 2,413,128 bytes
  • Total Incl. PeakMemUse (bytes): 1,856,064 bytes
  • Number of Function Calls: 5,515

Note:

This warning will still pop up, even if you limit your collection before. To get rid of this message use $collection->getLastItem() instead.

GetFirstItem

getFirstItem() does not limit the result of collection load to one item.

incorrect:

$collection = Mage::getModel('catalog/category')
    ->load(41)
    ->getProductCollection()
    ->addAttributeToSelect('weight');

$product = $collection->getFirstItem();
$weight  = $product->getData('weight');

correct:

Apply limit before grab data.

$collection->getSelect()->limit(1)

or

$collection->setPageSize(1, 1)

Expamples:

Collection with 750 products ...

Without limiting before:

  • Total Incl. Wall Time (microsec): 2,116,522 microsecs
  • Total Incl. CPU (microsecs): 2,101,688 microsecs
  • Total Incl. MemUse (bytes): 4,783,504 bytes
  • Total Incl. PeakMemUse (bytes): 4,363,112 bytes
  • Number of Function Calls: 104,187

With using getSelect()->limit(1):

  • Total Incl. Wall Time (microsec): 149,803 microsecs
  • Total Incl. CPU (microsecs): 131,405 microsecs
  • Total Incl. MemUse (bytes): 2,384,840 bytes
  • Total Incl. PeakMemUse (bytes): 1,827,112 bytes
  • Number of Function Calls: 5,327

With using setPageSize(1, 1)

  • Total Incl. Wall Time (microsec): 155,025 microsecs
  • Total Incl. CPU (microsecs): 136,191 microsecs
  • Total Incl. MemUse (bytes): 2,413,128 bytes
  • Total Incl. PeakMemUse (bytes): 1,856,064 bytes
  • Number of Function Calls: 5,515

Note:

This warning will still pop up, even if you limit your collection before. To get rid of this message use $collection->getLastItem() instead.

2 deleted 3 characters in body
source | link

GetFirstItem

GetFirstItem

getFirstItem() does not limit the result of collection load to one item.

incorrect:

$collection = Mage::getModel('catalog/category')
    ->load(41)
    ->getProductCollection()
    ->addAttributeToSelect('weight');

$product = $collection->getFirstItem();
$weight  = $product->getData('weight');

correct:

Apply limit before grab data.

$collection->getSelect()->limit(1)

or

$collection->setPageSize(1, 1)

Expamples:

Collection with 750 product:

$collection = Mage::getModel('catalog/category')
    ->load(41)
    ->getProductCollection()
    ->addAttributeToSelect('weight');
$product = $collection->getFirstItem();
$weight  = $product->getData('weight');

Without limiting before:

  • Total Incl. Wall Time (microsec): 2,116,522 microsecs
  • Total Incl. CPU (microsecs): 2,101,688 microsecs
  • Total Incl. MemUse (bytes): 4,783,504 bytes
  • Total Incl. PeakMemUse (bytes): 4,363,112 bytes
  • Number of Function Calls: 104,187

With using getSelect()->limit(1):

  • Total Incl. Wall Time (microsec): 149,803 microsecs
  • Total Incl. CPU (microsecs): 131,405 microsecs
  • Total Incl. MemUse (bytes): 2,384,840 bytes
  • Total Incl. PeakMemUse (bytes): 1,827,112 bytes
  • Number of Function Calls: 5,327

With using setPageSize(1, 1)

  • Total Incl. Wall Time (microsec): 155,025 microsecs
  • Total Incl. CPU (microsecs): 136,191 microsecs
  • Total Incl. MemUse (bytes): 2,413,128 bytes
  • Total Incl. PeakMemUse (bytes): 1,856,064 bytes
  • Number of Function Calls: 5,515

Note:

This warning will still pop up, even if you limit your collection before. To get rid of this message use $collection->getLastItem() instead.

GetFirstItem

incorrect:

$collection = Mage::getModel('catalog/category')
    ->load(41)
    ->getProductCollection()
    ->addAttributeToSelect('weight');

$product = $collection->getFirstItem();
$weight  = $product->getData('weight');

correct:

Apply limit before grab data.

$collection->getSelect()->limit(1)

or

$collection->setPageSize(1, 1)

Expamples:

Collection with 750 product:

$collection = Mage::getModel('catalog/category')
    ->load(41)
    ->getProductCollection()
    ->addAttributeToSelect('weight');
$product = $collection->getFirstItem();
$weight  = $product->getData('weight');

Without limiting before:

  • Total Incl. Wall Time (microsec): 2,116,522 microsecs
  • Total Incl. CPU (microsecs): 2,101,688 microsecs
  • Total Incl. MemUse (bytes): 4,783,504 bytes
  • Total Incl. PeakMemUse (bytes): 4,363,112 bytes
  • Number of Function Calls: 104,187

With using getSelect()->limit(1):

  • Total Incl. Wall Time (microsec): 149,803 microsecs
  • Total Incl. CPU (microsecs): 131,405 microsecs
  • Total Incl. MemUse (bytes): 2,384,840 bytes
  • Total Incl. PeakMemUse (bytes): 1,827,112 bytes
  • Number of Function Calls: 5,327

With using setPageSize(1, 1)

  • Total Incl. Wall Time (microsec): 155,025 microsecs
  • Total Incl. CPU (microsecs): 136,191 microsecs
  • Total Incl. MemUse (bytes): 2,413,128 bytes
  • Total Incl. PeakMemUse (bytes): 1,856,064 bytes
  • Number of Function Calls: 5,515

Note:

This warning will still pop up, even if you limit your collection before. To get rid of this message use $collection->getLastItem() instead.

GetFirstItem

getFirstItem() does not limit the result of collection load to one item.

incorrect:

$collection = Mage::getModel('catalog/category')
    ->load(41)
    ->getProductCollection()
    ->addAttributeToSelect('weight');

$product = $collection->getFirstItem();
$weight  = $product->getData('weight');

correct:

Apply limit before grab data.

$collection->getSelect()->limit(1)

or

$collection->setPageSize(1, 1)

Expamples:

Collection with 750 product:

$collection = Mage::getModel('catalog/category')
    ->load(41)
    ->getProductCollection()
    ->addAttributeToSelect('weight');
$product = $collection->getFirstItem();
$weight  = $product->getData('weight');

Without limiting before:

  • Total Incl. Wall Time (microsec): 2,116,522 microsecs
  • Total Incl. CPU (microsecs): 2,101,688 microsecs
  • Total Incl. MemUse (bytes): 4,783,504 bytes
  • Total Incl. PeakMemUse (bytes): 4,363,112 bytes
  • Number of Function Calls: 104,187

With using getSelect()->limit(1):

  • Total Incl. Wall Time (microsec): 149,803 microsecs
  • Total Incl. CPU (microsecs): 131,405 microsecs
  • Total Incl. MemUse (bytes): 2,384,840 bytes
  • Total Incl. PeakMemUse (bytes): 1,827,112 bytes
  • Number of Function Calls: 5,327

With using setPageSize(1, 1)

  • Total Incl. Wall Time (microsec): 155,025 microsecs
  • Total Incl. CPU (microsecs): 136,191 microsecs
  • Total Incl. MemUse (bytes): 2,413,128 bytes
  • Total Incl. PeakMemUse (bytes): 1,856,064 bytes
  • Number of Function Calls: 5,515

Note:

This warning will still pop up, even if you limit your collection before. To get rid of this message use $collection->getLastItem() instead.

1
source | link

GetFirstItem

incorrect:

$collection = Mage::getModel('catalog/category')
    ->load(41)
    ->getProductCollection()
    ->addAttributeToSelect('weight');

$product = $collection->getFirstItem();
$weight  = $product->getData('weight');

correct:

Apply limit before grab data.

$collection->getSelect()->limit(1)

or

$collection->setPageSize(1, 1)

Expamples:

Collection with 750 product:

$collection = Mage::getModel('catalog/category')
    ->load(41)
    ->getProductCollection()
    ->addAttributeToSelect('weight');
$product = $collection->getFirstItem();
$weight  = $product->getData('weight');

Without limiting before:

  • Total Incl. Wall Time (microsec): 2,116,522 microsecs
  • Total Incl. CPU (microsecs): 2,101,688 microsecs
  • Total Incl. MemUse (bytes): 4,783,504 bytes
  • Total Incl. PeakMemUse (bytes): 4,363,112 bytes
  • Number of Function Calls: 104,187

With using getSelect()->limit(1):

  • Total Incl. Wall Time (microsec): 149,803 microsecs
  • Total Incl. CPU (microsecs): 131,405 microsecs
  • Total Incl. MemUse (bytes): 2,384,840 bytes
  • Total Incl. PeakMemUse (bytes): 1,827,112 bytes
  • Number of Function Calls: 5,327

With using setPageSize(1, 1)

  • Total Incl. Wall Time (microsec): 155,025 microsecs
  • Total Incl. CPU (microsecs): 136,191 microsecs
  • Total Incl. MemUse (bytes): 2,413,128 bytes
  • Total Incl. PeakMemUse (bytes): 1,856,064 bytes
  • Number of Function Calls: 5,515

Note:

This warning will still pop up, even if you limit your collection before. To get rid of this message use $collection->getLastItem() instead.