Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce getId calls #3007

Merged
merged 1 commit into from
Feb 9, 2023
Merged

Reduce getId calls #3007

merged 1 commit into from
Feb 9, 2023

Conversation

luigifab
Copy link
Contributor

@luigifab luigifab commented Feb 2, 2023

Description

This reduce number of getItemId() calls (found with Blackfire).
Same as #2957 #2677 #2699 #1571.

before (with a big cart with 51 downloadable, simple and bundle products):
before-getitemid

after:
after-getitemid

To check the PR, I added if ($quoteItemId != $quoteItem->getItemId()) exit('boom');.
Yes this will not change many things, but this + many others...

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)
  • Add yourself to contributors list

@github-actions github-actions bot added the Component: CatalogInventory Relates to Mage_CatalogInventory label Feb 2, 2023
Copy link
Contributor

@Flyingmana Flyingmana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see question in code

@@ -273,8 +273,8 @@ protected function _removeErrorsFromQuoteAndItem($item, $code)
$canRemoveErrorFromQuote = true;

/** @var Mage_Sales_Model_Quote_Item $quoteItem */
foreach ($quoteItems as $quoteItem) {
if ($quoteItem->getItemId() == $item->getItemId()) {
foreach ($quoteItems as $quoteItemId => $quoteItem) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the ID coming from in the Collection? As far as I see its build in most of the cases without the itemId as key.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would an alternate be to actually code getItemId() instead of relying on the __call() method?

Copy link
Contributor Author

@luigifab luigifab Feb 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that majority of collection have the "id" as key?
From lib/Varien/Data/Collection.php, there are some references for id used as key. But perhaps I'm wrong.

From the method load of a collection, there is something about the id:

if (is_array($data)) {
foreach ($data as $row) {
$item = $this->getNewEmptyItem();
if ($this->getIdFieldName()) {
$item->setIdFieldName($this->getIdFieldName());
}
$item->addData($row);
$item->setDataChanges(false);
$this->addItem($item);
}

public function addItem(Varien_Object $item)
{
$itemId = $this->_getItemId($item);
if (!is_null($itemId)) {
if (isset($this->_items[$itemId])) {
throw new Exception('Item (' . get_class($item) . ') with the same id "' . $item->getId() . '" already exist');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The item id is indeed the key for all collections.

@fballiano fballiano merged commit e21216a into OpenMage:1.9.4.x Feb 9, 2023
fballiano pushed a commit that referenced this pull request Feb 9, 2023
@fballiano
Copy link
Contributor

merged and cherrypicked to v20

@luigifab luigifab deleted the getitemid branch February 9, 2023 10:07
elidrissidev pushed a commit to elidrissidev/magento-lts that referenced this pull request Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: CatalogInventory Relates to Mage_CatalogInventory
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants