Skip to content

30349: Product filter with category_id does not work as expected - fi… #30375

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

Conversation

sudheers-kensium
Copy link
Contributor

Product filter with category_id does not work as expected

Description (*)

  1. Create 2 categories with 1 product each
  2. run query to fetch products in those categories
    { products(filter: {category_id: {in: ["<cat1>", "<cat2>"]}}) { items { sku name } total_count } }
  3. Should display total_count should be 2, and items should contain 2 products

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes [PAP] Product filter with "category_id: {in: [...]}" does not work as expected #30349

Manual testing scenarios (*)

Questions or comments

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 Oct 8, 2020

Hi @sudheers-kensium. 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

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

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

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@sidolov sidolov added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Severity: S1 Affects critical data or functionality and forces users to employ a workaround. labels Oct 8, 2020
@rogyar rogyar self-assigned this Oct 9, 2020
@@ -61,7 +61,6 @@ public function apply(Filter $filter, AbstractDb $collection)
$category = $this->categoryFactory->create();
$this->categoryResourceModel->load($category, $categoryId);
$categoryProducts[$categoryId] = $category->getProductCollection()->getAllIds();
$collection->addCategoryFilter($category);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @sudheers-kensium. Thank you for your contribution. I'm not sure that by removing this filter we won't introduce an additional issue. This filter has been recently added for solving the sorting issue. Details are below

dfcf474#diff-8a27c9476b188f4e8830e9872984bdfbR64

@cpartica could you provide more information on the consequences, please? Unfortunately, I have a lack of details about MC-32278.

Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rogyar I have changed the code. Please check once.

@engcom-Charlie
Copy link
Contributor

Hi @sudheers-kensium, can you please look at #30375 (comment)? Otherwise, we can't proceed with your PR.
Thank you.

@nrkapoor
Copy link

@magento run all tests

@nrkapoor nrkapoor added this to the 2.4.2 milestone Oct 14, 2020
@engcom-Charlie engcom-Charlie removed their assignment Oct 15, 2020
@rogyar
Copy link
Contributor

rogyar commented Oct 17, 2020

Hi @sudheers-kensium. Thanks for the adjustments. Now it looks much better.
Could you, please, cover this case with an API-functional test?

Thank you!

@rogyar rogyar added the Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests label Oct 17, 2020
@sudheers-kensium
Copy link
Contributor Author

Hi @rogyar. I have added API-functional test. Please check once.

@sudheers-kensium
Copy link
Contributor Author

@magento run all tests

@cpartica cpartica added the PAP Partners acceleration program label Oct 21, 2020
@prabhuram93
Copy link
Contributor

@magento run integration tests

@sudheers-kensium
Copy link
Contributor Author

@magento run Integration Tests

@dthampy
Copy link
Contributor

dthampy commented Oct 22, 2020

@magento import PR to magento-honey-badgers/magento2ce

@magento-engcom-team
Copy link
Contributor

@dthampy the branch with code successfully imported intomagento-honey-badgers/magento2ce repository. Branch name: imported-magento-magento2-30375.

@rogyar rogyar added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests and removed Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests labels Oct 27, 2020
@magento-engcom-team
Copy link
Contributor

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

@cpartica
Copy link
Contributor

@magento import PR to magento-honey-badgers/magento2ce

@magento-engcom-team
Copy link
Contributor

@cpartica the branch with code successfully imported intomagento-honey-badgers/magento2ce repository. Branch name: imported-magento-magento2-30375.

@magento-engcom-team magento-engcom-team merged commit f9706db into magento:2.4-develop Nov 3, 2020
@m2-assistant
Copy link

m2-assistant bot commented Nov 3, 2020

Hi @sudheers-kensium, 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.

Copy link
Contributor

@rani-priya rani-priya left a comment

Choose a reason for hiding this comment

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

@rogyar @cpartica and @prabhuram93 could you please review my observation

@@ -113,7 +113,7 @@ public function getList(
$searchResults = $this->searchResultsFactory->create();
$searchResults->setSearchCriteria($searchCriteriaForCollection);
$searchResults->setItems($collection->getItems());
$searchResults->setTotalCount($searchResult->getTotalCount());
$searchResults->setTotalCount($collection->getSize());
Copy link
Contributor

@rani-priya rani-priya Apr 1, 2021

Choose a reason for hiding this comment

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

Hi @sudheers-kensium ,

Here why we have changed $searchResult->getTotalCount() to $collection->getSize() ?

Actually my concern is when we call getSize() on collection then it will execute one sql query to the database and it will take some time but in $searchResult is itself an object and all the data is present in that object. so, to execute $searchResult->getTotalCount() system will take negligible time where as $collection->getSize() will take some time.

I checked the performance of both code by adding below code in /vendor/magento/module-catalog-graph-ql/Model/Resolver/Products/DataProvider/ProductSearch.php file of "getList" method after "$this->collectionPostProcessor->process($collection, $attributes);" code and checked the response time of both getSize and getTotalCount method.
$time1 = microtime(true);
echo "Total Count: ".$collection->getSize()."
";
$time2 = microtime(true);
echo "time taken in getSize is: ".($time2- $time1)."
";

$time3 = microtime(true);
echo "Total Count: ".$searchResult->getTotalCount()."
";
$time4 = microtime(true);
echo "time taken in getTotalCount is: ".($time4 - $time3);
Response on my local :
Total Count: 32310
time taken in getSize is: 3.1487860679626
Total Count: 32310
time taken in getTotalCount is: 3.4093856811523E-5

@rani-priya
Copy link
Contributor

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

Hi @rani-webkul. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

@drpayyne
Copy link
Contributor

@rogyar @cpartica and @prabhuram93 could you please review my observation

Hi @rogyar, could you please check the above observation by @rani-webkul? Looks like it might cause performance issues when scaling up.

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 Component: CatalogGraphQl PAP Partners acceleration program Partner: Kensium Solutions LLC partners-contribution Pull Request is created by Magento Partner Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Project: GraphQL Release Line: 2.4 Severity: S1 Affects critical data or functionality and forces users to employ a workaround.
Projects
None yet