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

#26708 Fix: ORDER BY has two similar conditions in the SQL query #27263

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/code/Magento/Catalog/Block/Product/ListProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ public function getIdentities()
}

foreach ($this->_getProductCollection() as $item) {
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
$identities = array_merge($identities, $item->getIdentities());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If possible not to use '// phpcs:ignore Magento2.Performance.ForeachArrayMerge'

 $arraysItemsToMerge = [];
 foreach ($this->_getProductCollection() as $item) {
     $arraysItemsToMerge[] = $item->getIdentities();
 }
 $identities = array_merge($identities, ...$arraysItemsToMerge);

Copy link
Author

Choose a reason for hiding this comment

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

Hi @engcom-Echo,
Should we leave this part of the code as it was? We did not change it but because of this, there is a failed test. How we should proceed here? Any suggestions?
Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Using 'array_merge' function in a 'for/foreach/while'.
It's a very bad practice because it's a performance killer (especially in memory).

I think if we can change it for the better, it will be very good.

Copy link
Author

Choose a reason for hiding this comment

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

@engcom-Echo why should we change it in the scope of this PR if we didn't introduce it or modified it in the scope of this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @engcom-Echo, I have briefly checked, and looks like we aren't able replace it with anything. I was checking maybe we could use + operator here, but it may bring some unexpected behavior.
The main reason, being that + will remove the duplicated array values, in comparison with array_merge which just pushes the new array at the end of another one.

So I'd suggest to proceed with another investigation (separately), of how and where exactly these identities are used, and see if we are able to remove the duplicated array values.

What do you think?
Thank you.

Copy link
Contributor

Choose a reason for hiding this comment

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

So I'd suggest to proceed with another investigation (separately)....

Here I agree with you. Thanks for the discussion.


Expand Down Expand Up @@ -475,8 +476,6 @@ private function initializeProductCollection()
$layer->setCurrentCategory($origCategory);
}

$this->addToolbarBlock($collection);

$this->_eventManager->dispatch(
'catalog_block_product_list_collection',
['collection' => $collection]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ public function testGetIdentities()
->method('getProductCollection')
->will($this->returnValue($this->prodCollectionMock));

$this->layoutMock->expects($this->once())
->method('getBlock')
->will($this->returnValue($this->toolbarMock));

$this->assertEquals(
[$categoryTag, $productTag],
$this->block->getIdentities()
Expand Down