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

Added getScopeCacheKey in order to define the right cache key based on store ID #27142

Open
wants to merge 9 commits into
base: 2.5-develop
Choose a base branch
from

Conversation

matiashidalgo
Copy link
Contributor

@matiashidalgo matiashidalgo commented Mar 3, 2020

Description (*)

This PR adds an small improvement to the instance cache into the categories repository cause it allows to receive store id or store code for attributes data retrieval but at the same time this store id / code is used as cache key which make it a double unnecessary category load when you request the category by same given store, first providing the store id and then providing store code.

Manual testing scenarios (*)

  1. Into your own class load the category repository via di.
  2. Use the category repository to get a given category providing an specific store ID. Check the given category got stored into the cached instances array of the repository under the store ID.
  3. Use the category repository to get a given category (same category as previous point) providing a specific store Code (same store as previous point). Error should be thrown with this fix, otherwise it was loading again the category filtering by store code which is incorrect based on PHP Docs into the interface.

Questions or comments

Have in mind this issue is not reproducible from REST API given it enforces to use the store ID based on the PHP Docs from the interface.

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)

Resolved issues:

  1. resolves [Issue] Added getScopeCacheKey in order to define the right cache key based on store ID #28142: Added getScopeCacheKey in order to define the right cache key based on store ID

@m2-assistant
Copy link

m2-assistant bot commented Mar 3, 2020

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

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

Hi @matiashidalgo,

According to phpdoc block https://github.com/magento/magento2/blob/8c36ea51fab3be7d3e2135c2e4cc386bd453673c/app/code/Magento/Catalog/Api/CategoryRepositoryInterface.php#L29
this class should retrieve only int, so we don't need to support other possible cases. So looks like we don't really need to fix it, as it's not an issue at all

Do you have this issue in magento core or in custom module?

@matiashidalgo
Copy link
Contributor Author

Hi @matiashidalgo,

According to phpdoc block

https://github.com/magento/magento2/blob/8c36ea51fab3be7d3e2135c2e4cc386bd453673c/app/code/Magento/Catalog/Api/CategoryRepositoryInterface.php#L29

this class should retrieve only int, so we don't need to support other possible cases. So looks like we don't really need to fix it, as it's not an issue at all
Do you have this issue in magento core or in custom module?

As I said into the comments, the interface enforce it for API requests, but it doesn't work that way for instantiation from code, I saw the tests and I'll make a little change to the implementation.

@ihor-sviziev
Copy link
Contributor

@matiashidalgo
In this case maybe it’s better to throw an exception

@lbajsarowicz
Copy link
Contributor

lbajsarowicz commented Mar 3, 2020

@ihor-sviziev I was the one who reported that issue internally for contribution.
During work with #27035 I faced the situation where as a second argument of the function internally was used Store Code instead of Store ID.

Change to throw Exception (or type hint for argument to ?int would be backward incompatible. But it's also an option, actually.

--- EDIT
@matiashidalgo I spoke to @ihor-sviziev and actually it's good approach to throw an exception on invalid type. Then we'll see which API functional tests fail and fix these references with Store Code.

@matiashidalgo matiashidalgo force-pushed the mhidalgo/added-scope-cache-key-for-category-repository branch from 8c36ea5 to 69946cc Compare March 4, 2020 19:14
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

Hi @matiashidalgo,
I've added few comments, please adjust your solution.

There also some integration test failed because it used string store code instead of numeric id. Please fix it.

app/code/Magento/Catalog/Model/CategoryRepository.php Outdated Show resolved Hide resolved
app/code/Magento/Catalog/Model/CategoryRepository.php Outdated Show resolved Hide resolved
app/code/Magento/Catalog/Model/CategoryRepository.php Outdated Show resolved Hide resolved
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

Hi @matiashidalgo,
Your changes looks good to me. Could you cover your changes with tests, for instance unit tests?

@ihor-sviziev ihor-sviziev added the Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests label Mar 6, 2020
@ihor-sviziev
Copy link
Contributor

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

@ihor-sviziev ihor-sviziev added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: test coverage and removed Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests labels Mar 11, 2020
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

Failing functional tests are not related to changes in this pr

…go/added-scope-cache-key-for-category-repository
@matiashidalgo
Copy link
Contributor Author

@ihor-sviziev I've updated this branch, now pointing out to 2.5-develop and fixed conflicting files

@ihor-sviziev
Copy link
Contributor

@magento run all tests

@matiashidalgo
Copy link
Contributor Author

@magento run all tests

@ihor-sviziev
Copy link
Contributor

@magento run Unit Tests, Functional Tests CE

@ihor-sviziev
Copy link
Contributor

@magento run Functional Tests B2B, Functional Tests CE

@ihor-sviziev
Copy link
Contributor

@magento run Functional Tests CE

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 Award: test coverage Component: Catalog Partner: Blue Acorn iCi Partner: Mediotype partners-contribution Pull Request is created by Magento Partner Priority: P4 No current plan to fix. Fixing can be deferred as a logical part of more important work. Progress: ready for testing QA: Ready to add to Regression Scope Should be analyzed and added to Regression Testing Scope(if applicable) Release Line: 2.5 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Status: Ready for Testing
Development

Successfully merging this pull request may close these issues.

[Issue] Added getScopeCacheKey in order to define the right cache key based on store ID