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

Conversation

vasilii-b
Copy link

@vasilii-b vasilii-b commented Mar 12, 2020

Description (*)

The PR fixes two similar order by condition in the SQL query of the app/code/Magento/Catalog/Block/Product/ListProduct.php

Related Pull Requests

#26754 - Original PR (the author gave up on the PR #26754 (comment))
#11473 - PR that introduced the issue

Fixed Issues (if relevant)

  1. ORDER BY has two similar conditions #26708: ORDER BY has two similar conditions

Manual testing scenarios (*)

Please see #26708

Questions or comments

@lenaorobei Could you please follow this PR, as you already did the review of the closed one #11473.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Mar 12, 2020

Hi @vasilii-b. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@magento-engcom-team magento-engcom-team added Component: Catalog Release Line: 2.4 Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner labels Mar 12, 2020
@eduard13 eduard13 self-assigned this Mar 12, 2020
@ihor-sviziev
Copy link
Contributor

It seems to me related to #26934

@eduard13
Copy link
Contributor

@ihor-sviziev in my opinion isn't exactly the same, but I'd additionally check if this affects somehow the product listing with Elastic Search enabled. Moreover, I see that there are couple of failing tests related to ElasticSearch.

@vasilii-b vasilii-b force-pushed the 26708-order-by-sql-select-duplicated branch from 5720637 to 1e1ebd3 Compare March 18, 2020 12:51
@vasilii-b
Copy link
Author

Hi @eduard13,
Could you please advise on the failed tests? The failed functional tests seem not related to the changes in this PR. Also, the static failed test points to a part of the code that was not changed in the scope of this PR.

Thank you!

@eduard13 eduard13 added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix labels Mar 19, 2020
@eduard13
Copy link
Contributor

@magento run all tests

Copy link
Contributor

@eduard13 eduard13 left a comment

Choose a reason for hiding this comment

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

The failing tests aren't related to these changes.
Thank you for your collaboration.

@magento-engcom-team
Copy link
Contributor

Hi @eduard13, thank you for the review.
ENGCOM-7144 has been created to process this Pull Request

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

Before:
screenshot1

After:
screenshot2

@@ -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.

@engcom-Echo
Copy link
Contributor

Failed functional tests not related to the changes in this PR

@m2-assistant
Copy link

m2-assistant bot commented Mar 21, 2020

Hi @vasilii-b, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix Component: Catalog Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner Progress: accept Release Line: 2.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants