adobe / aem-core-cif-components

A set of configurations and components to get you started with AEM Commerce development
Apache License 2.0
103 stars 80 forks source link

CIF-2916: add UrlProvider product and category filter hooks #943

Closed buuhuu closed 2 years ago

buuhuu commented 2 years ago

Description

Currently the UrlProvider has to do a query when a component wants to get the product identifier (sku) or category (uid) and the requested value cannot be parsed from the url by the url format. Usually this identifier is later used by the components to query for either the product (e.g product detail, breadcrumb, related products) or some category data.

This change moves this one query done by the UrlProvider in some cases to further reduce the number of graphql request per page. It does so by extending the retrieves with a product / category filter hook obtained from the UrlProvider. These hooks have access to the parameters the url format can parse from the url and construct the filter input accordingly.

Furthermore the request-local caching implemented in the MagentoGraphqlClientImpl got extended to respond also for partially matching queries (a very simple form of a higher level graphql cache). This helps for example any commerce content fragment or commerce experience fragment on a product detail page, as they can reuse the response from the product detail query (that contains the sku they get from the UrlProvider#getProductIdentifier()).

In Venia that means:

Some details about the changes:

Related Issue

CIF-2916 https://github.com/adobe/aem-core-cif-components/pull/938

Motivation and Context

Each graphql query that is executed during page rendering comes on a cost, essentially blocking the rendering until the response is received. The query done by the url provider usually is fast but the unnecessary network round trip can still be avoided.

How Has This Been Tested?

Unit tests

Screenshots (if appropriate):

Types of changes

Checklist:

codecov[bot] commented 2 years ago

Codecov Report

Merging #943 (61cccca) into master (78f1845) will decrease coverage by 0.19%. The diff coverage is 88.93%.

@@             Coverage Diff              @@
##             master     #943      +/-   ##
============================================
- Coverage     89.57%   89.37%   -0.20%     
- Complexity     2172     2187      +15     
============================================
  Files           352      350       -2     
  Lines          9764     9828      +64     
  Branches       1405     1414       +9     
============================================
+ Hits           8746     8784      +38     
- Misses          727      745      +18     
- Partials        291      299       +8     
Flag Coverage Δ
integration 51.99% <69.91%> (+0.37%) :arrow_up:
jest 86.55% <ø> (ø)
karma 95.33% <ø> (ø)
unittests 87.98% <87.61%> (-0.46%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rce/core/components/services/urls/UrlProvider.java 100.00% <ø> (ø)
.../components/internal/services/UrlProviderImpl.java 83.20% <80.00%> (-3.76%) :arrow_down:
...ch/internal/services/SearchResultsServiceImpl.java 94.37% <83.33%> (-0.81%) :arrow_down:
...nternal/models/v1/productlist/ProductListImpl.java 89.08% <85.71%> (-3.13%) :arrow_down:
...onents/internal/models/v1/product/ProductImpl.java 87.50% <88.05%> (+0.90%) :arrow_up:
...s/v1/relatedproducts/RelatedProductsRetriever.java 96.77% <91.66%> (+0.34%) :arrow_up:
...ents/internal/client/MagentoGraphqlClientImpl.java 96.91% <100.00%> (+0.16%) :arrow_up:
.../internal/models/v1/breadcrumb/BreadcrumbImpl.java 91.42% <100.00%> (-0.39%) :arrow_down:
...rnal/models/v1/breadcrumb/BreadcrumbRetriever.java 95.71% <100.00%> (+1.68%) :arrow_up:
...s/internal/models/v1/product/ProductRetriever.java 100.00% <100.00%> (ø)
... and 13 more

Help us with your feedback. Take ten seconds to tell us how you rate us.