-
Notifications
You must be signed in to change notification settings - Fork 346
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
base: canary
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -255,7 +255,7 @@ export const getStreamableProductVariant = cache( | |
| document: StreamableProductVariantBySkuQuery, | ||
| variables, | ||
| customerAccessToken, | ||
| fetchOptions: customerAccessToken ? { cache: 'no-store' } : { next: { revalidate } }, | ||
| fetchOptions: { cache: 'no-store' }, | ||
|
Collaborator
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 to be removing caching from the existing query for product variants. Was this intentional? If the query is specifically for variant inventory quantities, can we update the query name to be explicit about that. |
||
| }); | ||
|
|
||
| return data.site.product?.variants; | ||
|
|
@@ -306,6 +306,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 | ||
|
|
@@ -320,25 +350,23 @@ const StreamableProductQuery = graphql( | |
| availabilityV2 { | ||
| status | ||
| } | ||
| ...ProductViewedFragment | ||
| ...ProductVariantsInventoryFragment | ||
| ...ProductSchemaFragment | ||
| } | ||
| } | ||
| } | ||
| `, | ||
| [ProductViewedFragment, ProductSchemaFragment, ProductVariantsInventoryFragment], | ||
| [ProductVariantsInventoryFragment], | ||
| ); | ||
|
|
||
| type Variables = VariablesOf<typeof StreamableProductQuery>; | ||
| type ProductInventoryVariables = VariablesOf<typeof StreamableProductQuery>; | ||
|
|
||
| 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: { cache: 'no-store' }, | ||
|
Collaborator
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. Is |
||
| }); | ||
|
|
||
| return data.site.product; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ import { | |
| getProductPricingAndRelatedProducts, | ||
| getStreamableInventorySettingsQuery, | ||
| getStreamableProduct, | ||
| getStreamableProductInventory, | ||
| getStreamableProductVariant, | ||
| } from './page-data'; | ||
|
|
||
|
|
@@ -117,8 +118,22 @@ export default async function Product({ params, searchParams }: Props) { | |
|
|
||
| const streamableProductSku = Streamable.from(async () => (await streamableProduct).sku); | ||
|
|
||
| const streamableProductInventory = Streamable.from(async () => { | ||
| const variables = { | ||
| entityId: Number(productId), | ||
| }; | ||
|
|
||
| const product = await getStreamableProductInventory(variables, customerAccessToken); | ||
|
|
||
| if (!product) { | ||
| return notFound(); | ||
| } | ||
|
|
||
| return product; | ||
| }); | ||
|
|
||
| const streamableProductVariant = Streamable.from(async () => { | ||
| const product = await streamableProduct; | ||
| const product = await streamableProductInventory; | ||
|
Comment on lines
135
to
+136
Collaborator
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. Shouldn't the variable name change if this is specifically tracking product inventory? |
||
|
|
||
| if (!product.inventory.hasVariantInventory) { | ||
| return undefined; | ||
|
|
@@ -188,7 +203,7 @@ export default async function Product({ params, searchParams }: Props) { | |
| }); | ||
|
|
||
| const streameableCtaLabel = Streamable.from(async () => { | ||
| const product = await streamableProduct; | ||
| const product = await streamableProductInventory; | ||
|
|
||
| if (product.availabilityV2.status === 'Unavailable') { | ||
| return t('ProductDetails.Submit.unavailable'); | ||
|
|
@@ -206,7 +221,7 @@ export default async function Product({ params, searchParams }: Props) { | |
| }); | ||
|
|
||
| const streameableCtaDisabled = Streamable.from(async () => { | ||
| const product = await streamableProduct; | ||
| const product = await streamableProductInventory; | ||
|
|
||
| if (product.availabilityV2.status === 'Unavailable') { | ||
| return true; | ||
|
|
@@ -253,7 +268,7 @@ export default async function Product({ params, searchParams }: Props) { | |
|
|
||
| const streamableStockDisplayData = Streamable.from(async () => { | ||
| const [product, variant, inventorySetting] = await Streamable.all([ | ||
| streamableProduct, | ||
| streamableProductInventory, | ||
| streamableProductVariant, | ||
| streamableInventorySettings, | ||
| ]); | ||
|
|
@@ -343,7 +358,7 @@ export default async function Product({ params, searchParams }: Props) { | |
|
|
||
| const streamableBackorderDisplayData = Streamable.from(async () => { | ||
| const [product, variant, inventorySetting] = await Streamable.all([ | ||
| streamableProduct, | ||
| streamableProductInventory, | ||
| streamableProductVariant, | ||
| streamableInventorySettings, | ||
| ]); | ||
|
|
||
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?