Open mandarzope opened 2 years ago
Hi @mandarzope. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:
Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release
For more details, review the Magento Contributor Assistant documentation.
Add a comment to assign the issue: @magento I am working on this
To learn more about issue processing workflow, refer to the Code Contributions.
Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
@magento give me 2.4-develop instance
Hi @mandarzope. Thank you for your request. I'm working on Magento instance for you.
Hi @mandarzope, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.
Hi @engcom-Echo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.Issue: Clear Description
label to the issue by yourself.Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.2.4-develop
branch@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure. 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.Hi @mandarzope,
Thank you for reporting the issue.
Issue is verified and reproduced on Magento 2.4-develop. Below are the steps I did to reproduce it:
x-magento-cache-debug
is coming as MISS
. cache-control
is showing no-cache
. Attached screenshot of same:Based on the above analysis, confirming the issue.
Thanks
:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-2059 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Echo. Thank you for verifying the issue.
Issue Available: @engcom-Echo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
The issue here is very similar for both Products and CMS pages.
For products, data is provided by https://github.com/magento/magento2/blob/cfaeeaef415c2a77009db57995e5eee627350878/app/code/Magento/CatalogUrlRewriteGraphQl/Model/DataProvider/UrlRewrite/ProductDataProvider.php
For CMS pages, data is provided by https://github.com/magento/magento2/blob/cfaeeaef415c2a77009db57995e5eee627350878/app/code/Magento/CmsUrlRewriteGraphQl/Model/DataProvider/UrlRewrite/Page.php
Both of these data providers return data using the relevant repositories, so for products, we end up with entity_id
as part of the result array, while for CMS pages, we end up with page_id
.
However, when it comes to determining if a query is cacheable, we need to look at https://github.com/magento/magento2/blob/cfaeeaef415c2a77009db57995e5eee627350878/app/code/Magento/CatalogUrlRewriteGraphQl/Model/Resolver/UrlRewrite/CatalogUrlResolverIdentity.php and https://github.com/magento/magento2/blob/cfaeeaef415c2a77009db57995e5eee627350878/app/code/Magento/CmsUrlRewriteGraphQl/Model/Resolver/UrlRewrite/CmsUrlResolverIdentity.php
We can see in both cases, the code is looking specifically for the presence of id
in the resolved data. Since this doesn't exist in either case, no cache tags get added to the array of identities. Subsequently, the query is considered to not be cacheable, and the no-cache headers are added.
My suggestion would be for one of the following two things to happen:
CatalogUrlResolverIdentity
to use entity_id
instead of id
. This class is also used for categories, but since they also have an entity id, this should still work. Similarly, change CmsUrlResolverIdentity
to use page_id
instead of id
.id
value based on entity_id
(for products) or page_id
(for CMS pages.The issue here is very similar for both Products and CMS pages.
For products, data is provided by https://github.com/magento/magento2/blob/cfaeeaef415c2a77009db57995e5eee627350878/app/code/Magento/CatalogUrlRewriteGraphQl/Model/DataProvider/UrlRewrite/ProductDataProvider.php
For CMS pages, data is provided by https://github.com/magento/magento2/blob/cfaeeaef415c2a77009db57995e5eee627350878/app/code/Magento/CmsUrlRewriteGraphQl/Model/DataProvider/UrlRewrite/Page.php
Both of these data providers return data using the relevant repositories, so for products, we end up with
entity_id
as part of the result array, while for CMS pages, we end up withpage_id
.However, when it comes to determining if a query is cacheable, we need to look at https://github.com/magento/magento2/blob/cfaeeaef415c2a77009db57995e5eee627350878/app/code/Magento/CatalogUrlRewriteGraphQl/Model/Resolver/UrlRewrite/CatalogUrlResolverIdentity.php and https://github.com/magento/magento2/blob/cfaeeaef415c2a77009db57995e5eee627350878/app/code/Magento/CmsUrlRewriteGraphQl/Model/Resolver/UrlRewrite/CmsUrlResolverIdentity.php
We can see in both cases, the code is looking specifically for the presence of
id
in the resolved data. Since this doesn't exist in either case, no cache tags get added to the array of identities. Subsequently, the query is considered to not be cacheable, and the no-cache headers are added.My suggestion would be for one of the following two things to happen:
- Change
CatalogUrlResolverIdentity
to useentity_id
instead ofid
. This class is also used for categories, but since they also have an entity id, this should still work. Similarly, changeCmsUrlResolverIdentity
to usepage_id
instead ofid
.- Change the two data providers to additionally set the
id
value based onentity_id
(for products) orpage_id
(for CMS pages.
That will teach me to check an older version of the code - it appears this issue has already been fixed in 2.4-develop
(as can be seen in the code snippets above)
@engcom-Echo can you test this against the latest 2.4-develop code - I believe it should be fixed now (by this commit https://github.com/magento/magento2/commit/967439abee8e9e2e934aaa983748357dd8816b7d).
Apparently, the reason is that initially graphql requests are POST requests, so cache tags will not be assigned to them because of this condition
I had raised the PR in past (2 years back). However because I am not a contributor, these are not accepted.
Preconditions (*)
Steps to reproduce (*)
Expected result (*)
Actual result (*)
After debugging I have found that vendor/magento/module-cms-url-rewrite-graph-ql/Model/Resolver/UrlRewrite/CmsUrlResolverIdentity.php:26 vendor/magento/module-catalog-url-rewrite-graph-ql/Model/Resolver/UrlRewrite/CatalogUrlResolverIdentity.php:36
expects a key 'id' to be present in $resolvedData $ids = [$selectedCacheTag, sprintf('%s_%s', $selectedCacheTag, $resolvedData['id'])];
A workaround solution is to overwrite the files vendor/magento/module-catalog-url-rewrite-graph-ql/Model/DataProvider/UrlRewrite/ProductDataProvider.php:48 $product = $this->productRepository->getById($id, false, $storeId); $result = $product->getData(); $result['id'] = $product->getId();
vendor/magento/module-cms-url-rewrite-graph-ql/Model/DataProvider/UrlRewrite/Page.php:49 $result = $this->pageDataProvider->getDataByPageId((int)$id); $result['type_id'] = $entity_type; $result['id'] = $result['page_id']