Skip to content

Conversation

@Himsoft
Copy link
Contributor

@Himsoft Himsoft commented Feb 28, 2025

Description (*)

\Magento\Catalog\Model\ResourceModel\Product\Collection::addMediaGalleryData calls getSize if the collection is loaded.

  • Fixed call count instead of getSize if collection is loaded.

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Product Collection - addMediaGalleryData calls getSize when the collection maybe or will be loaded (Can use count to avoid an extra DB query) #39111

Manual testing scenarios (*)

  1. Enable dev query log
  2. Call the products GQL with the media_gallery/media_gallery_entries field selected.
  3. The method (getSize or count) call should be in the query log, traced to addMediaGalleryData

Before fix:
getSize is called on a loaded product collection

After fix:
count is called on a loaded product collection

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)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

… when the collection maybe or will be loaded (Can use count to avoid an extra DB query)

- Fixed call count instead of getSize if collection is loaded.
@m2-assistant
Copy link

m2-assistant bot commented Feb 28, 2025

Hi @Himsoft. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ 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
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@m2-github-services m2-github-services added Partner: Perspective partners-contribution Pull Request is created by Magento Partner labels Feb 28, 2025
@Himsoft
Copy link
Contributor Author

Himsoft commented Feb 28, 2025

@magento run all tests

… when the collection maybe or will be loaded (Can use count to avoid an extra DB query)

- Fixed call count instead of getSize if collection is loaded.
@Himsoft
Copy link
Contributor Author

Himsoft commented Feb 28, 2025

@magento run all tests

@Himsoft
Copy link
Contributor Author

Himsoft commented Feb 28, 2025

@magento run all tests

… when the collection maybe or will be loaded (Can use count to avoid an extra DB query)

- Fixed call count instead of getSize if collection is loaded.
@Himsoft
Copy link
Contributor Author

Himsoft commented Feb 28, 2025

@magento run all tests

@Himsoft
Copy link
Contributor Author

Himsoft commented Feb 28, 2025

The failed tests are not related to fixes, they look like false positives, please pay attention to this during the review.

@engcom-Bravo engcom-Bravo added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Mar 3, 2025
@Priyakshic Priyakshic added the Project: Community Picked PRs upvoted by the community label Mar 13, 2025
@Priyakshic Priyakshic moved this to Pending Review in Community Dashboard Mar 13, 2025
@engcom-Bravo engcom-Bravo added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Mar 17, 2025
@engcom-Hotel
Copy link
Contributor

@magento run all tests

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.

Files not reviewed (2)
  • app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php: Language not supported
  • app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/CollectionTest.php: Language not supported

Copy link
Contributor

@engcom-Hotel engcom-Hotel left a comment

Choose a reason for hiding this comment

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

Hello @Himsoft,

Thanks for the contribution!

The changes looks good to me, just one change as suggested below.

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2025 Adobe
Copy link
Contributor

Choose a reason for hiding this comment

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

This must be 2015, as the file created in this year only.

@engcom-Hotel engcom-Hotel moved this from Pending Review to Changes Requested in Community Dashboard Mar 28, 2025
… when the collection maybe or will be loaded (Can use count to avoid an extra DB query)

- Fixed call count instead of getSize if collection is loaded.
@Himsoft
Copy link
Contributor Author

Himsoft commented Mar 28, 2025

@magento run all tests

@engcom-Hotel engcom-Hotel moved this from Changes Requested to Pending Review in Community Dashboard Apr 1, 2025
@engcom-Hotel engcom-Hotel moved this from Review in Progress to Ready for Testing in Community Dashboard Apr 2, 2025
@engcom-Dash engcom-Dash self-assigned this Apr 3, 2025
@engcom-Dash engcom-Dash moved this from Ready for Testing to Testing in Progress in Community Dashboard Apr 3, 2025
@engcom-Dash
Copy link
Contributor

@magento run all tests

@engcom-Dash
Copy link
Contributor

@Himsoft Thank you for contribution & collaboration!

✔️ QA Passed

Preconditions:
Install Fresh Magento 2.4-develop

Steps to reproduce:

  1. Enable dev query log using command: "bin/magento dev:query-log:enable"
  2. Call the products Graphql with the media_gallery field selected.
Screenshot 2025-04-04 at 3 55 58 PM

Before:

As per PR description getSize() was getting called on already loaded collection which was increasing the call trace with one more query.

image

After:

Count() function is called if the collection is already loaded. only one trace found for addMediaGalleryData.

image

Added Loggers in the code to check is count getting called or not as the call was not there in the db.log

image

image

Functional Tests are failing hence moving this PR to Extended Testing.

@engcom-Dash engcom-Dash moved this from Testing in Progress to Extended testing (optional) in Community Dashboard Apr 4, 2025
@engcom-Dash
Copy link
Contributor

@magento run Functional Tests B2B, Functional Tests CE, Functional Tests EE

@engcom-Dash
Copy link
Contributor

All checks have been completed and the build is green. Hence moving this PR in Merge In Progress.

image

@engcom-Dash engcom-Dash moved this from Extended testing (optional) to Merge in Progress in Community Dashboard Apr 7, 2025
@magento-devops-reposync-svc magento-devops-reposync-svc merged commit 5388de0 into magento:2.4-develop Apr 16, 2025
12 checks passed
@engcom-Charlie engcom-Charlie moved this from Merge in Progress to Recently Merged in Community Dashboard Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Partner: Perspective 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. Progress: accept Project: Community Picked PRs upvoted by the community Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Projects

Status: Recently Merged

Development

Successfully merging this pull request may close these issues.

Product Collection - addMediaGalleryData calls getSize when the collection maybe or will be loaded (Can use count to avoid an extra DB query)

7 participants