-
Notifications
You must be signed in to change notification settings - Fork 349
feat: Remove caching on fetching product inventory data #2801
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| "@bigcommerce/catalyst-core": minor | ||
| --- | ||
|
|
||
| Fetch product inventory data with a separate GQL query with no caching | ||
|
|
||
| ## Migration | ||
| The files to be rebased for this change to be applied are: | ||
| - core/app/[locale]/(default)/product/[slug]/page-data.ts | ||
| - core/app/[locale]/(default)/product/[slug]/page.tsx | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,7 +210,7 @@ export const getProduct = cache(async (entityId: number, customerAccessToken?: s | |
| return data.site; | ||
| }); | ||
|
|
||
| const StreamableProductVariantBySkuQuery = graphql(` | ||
| const StreamableProductVariantInventoryBySkuQuery = graphql(` | ||
| query ProductVariantBySkuQuery($productId: Int!, $sku: String!) { | ||
| site { | ||
| product(entityId: $productId) { | ||
|
|
@@ -246,15 +246,15 @@ const StreamableProductVariantBySkuQuery = graphql(` | |
| } | ||
| `); | ||
|
|
||
| type VariantVariables = VariablesOf<typeof StreamableProductVariantBySkuQuery>; | ||
| type VariantInventoryVariables = VariablesOf<typeof StreamableProductVariantInventoryBySkuQuery>; | ||
|
|
||
| export const getStreamableProductVariant = cache( | ||
| async (variables: VariantVariables, customerAccessToken?: string) => { | ||
| export const getStreamableProductVariantInventory = cache( | ||
| async (variables: VariantInventoryVariables, customerAccessToken?: string) => { | ||
| const { data } = await client.fetch({ | ||
| document: StreamableProductVariantBySkuQuery, | ||
| document: StreamableProductVariantInventoryBySkuQuery, | ||
| variables, | ||
| customerAccessToken, | ||
| fetchOptions: customerAccessToken ? { cache: 'no-store' } : { next: { revalidate } }, | ||
| fetchOptions: customerAccessToken ? { cache: 'no-store' } : { next: { revalidate: 60 } }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems fine for now, but I have a feeling we might get push back from product on aligning on fresh data for stock count. |
||
| }); | ||
|
|
||
| return data.site.product?.variants; | ||
|
|
@@ -310,6 +310,36 @@ const StreamableProductQuery = graphql( | |
| minPurchaseQuantity | ||
| maxPurchaseQuantity | ||
| warranty | ||
| ...ProductViewedFragment | ||
| ...ProductSchemaFragment | ||
| } | ||
| } | ||
| } | ||
| `, | ||
| [ProductViewedFragment, ProductSchemaFragment], | ||
| ); | ||
|
|
||
| type Variables = VariablesOf<typeof StreamableProductQuery>; | ||
|
|
||
| export const getStreamableProduct = cache( | ||
| async (variables: Variables, customerAccessToken?: string) => { | ||
| const { data } = await client.fetch({ | ||
| document: StreamableProductQuery, | ||
| variables, | ||
| customerAccessToken, | ||
| fetchOptions: customerAccessToken ? { cache: 'no-store' } : { next: { revalidate } }, | ||
| }); | ||
|
|
||
| return data.site.product; | ||
| }, | ||
| ); | ||
|
|
||
| const StreamableProductInventoryQuery = graphql( | ||
| ` | ||
| query StreamableProductInventoryQuery($entityId: Int!) { | ||
| site { | ||
| product(entityId: $entityId) { | ||
| sku | ||
| inventory { | ||
| hasVariantInventory | ||
| isInStock | ||
|
|
@@ -324,25 +354,23 @@ const StreamableProductQuery = graphql( | |
| availabilityV2 { | ||
| status | ||
| } | ||
| ...ProductViewedFragment | ||
| ...ProductVariantsInventoryFragment | ||
| ...ProductSchemaFragment | ||
| } | ||
| } | ||
| } | ||
| `, | ||
| [ProductViewedFragment, ProductSchemaFragment, ProductVariantsInventoryFragment], | ||
| [ProductVariantsInventoryFragment], | ||
| ); | ||
|
|
||
| type Variables = VariablesOf<typeof StreamableProductQuery>; | ||
| type ProductInventoryVariables = VariablesOf<typeof StreamableProductQuery>; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this be better?
|
||
|
|
||
| export const getStreamableProduct = cache( | ||
| async (variables: Variables, customerAccessToken?: string) => { | ||
| export const getStreamableProductInventory = cache( | ||
| async (variables: ProductInventoryVariables, customerAccessToken?: string) => { | ||
| const { data } = await client.fetch({ | ||
| document: StreamableProductQuery, | ||
| document: StreamableProductInventoryQuery, | ||
| variables, | ||
| customerAccessToken, | ||
| fetchOptions: customerAccessToken ? { cache: 'no-store' } : { next: { revalidate } }, | ||
| fetchOptions: customerAccessToken ? { cache: 'no-store' } : { next: { revalidate: 60 } }, | ||
| }); | ||
|
|
||
| return data.site.product; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the rationale for marking this as a
minorthe impact it could have on performance and/or costs for the PDP?This is the primary question that I have when introducing queries that aren't cached. Are we good with every single PDP load invoking the API? Are we certain merchants won't run into rate limits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's minor because it has not major changes that impacts the UX much.
What happens with the current change is that only the product variant inventory data will be fetched with the PDP reload. So, product details and images as well as other settings data are not refetched.