fix(product): avoid loading all variants on scalar variant updates#14728
Open
avonian wants to merge 1 commit intomedusajs:developfrom
Open
fix(product): avoid loading all variants on scalar variant updates#14728avonian wants to merge 1 commit intomedusajs:developfrom
avonian wants to merge 1 commit intomedusajs:developfrom
Conversation
|
|
@avonian is attempting to deploy a commit to the medusajs Team on Vercel. A member of the Team first needs to authorize it. |
36c2f94 to
7e5f8e2
Compare
…ny variants Two fixes for variant update performance on products with many variants: 1. product-module-service: `updateVariants_()` unconditionally loads all sibling variants (with options) to check for duplicate option combos, even when options haven't changed. Move the query inside the conditional so it only runs when options are present in the update payload. 2. Route middleware: the variant POST/DELETE routes use `retrieveProductQueryConfig` which refetches the full product with ALL variants, prices, price rules, and options after a single variant update. For products with 400+ variants this refetch alone takes 10+ minutes. Use a lean product config that excludes variant relations — the admin dashboard already fetches variants separately via GET. Before: variant title update on product with 414 variants = 12+ minutes After: ~3 seconds (workflow) + fast refetch Fixes medusajs#14727
7e5f8e2 to
da6b1f0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes mutation response performance for products with many variants (400+).
The problem
Multiple product sub-resource mutation routes (variant CRUD, option CRUD) use
retrieveProductQueryConfigfor the post-mutationrefetchEntitycall. This config includes*variants,*variants.prices,variants.prices.price_rules.*,*variants.options— loading ALL variants with all their prices, rules, and options after a single sub-resource change.Profiling results on a product with 414 variants:
updateProductVariantsWorkflowrefetchEntitywith full product configThe admin dashboard already fetches variants separately via GET requests (using
fields=-variants). The mutation responses don't need to include all variant data.The fix
1. Lean product query config for sub-resource mutations
Added
retrieveProductWithoutVariantsQueryConfigthat filters out*variantsandvariants.*fields. Applied to these middleware configs:POST /admin/products/:id/variants(create variant)POST /admin/products/:id/variants/:variant_id(update variant)DELETE /admin/products/:id/variants/:variant_id(delete variant)POST /admin/products/:id/options(create option)POST /admin/products/:id/options/:option_id(update option)DELETE /admin/products/:id/options/:option_id(delete option)2. Conditional allVariants loading in
updateVariants_updateVariants_()unconditionally loads all sibling variants with options for thecheckIfVariantWithOptionsAlreadyExistsvalidation, even when options aren't being updated. Moved the query inside the conditional so it only runs when options are present in the update payload.Files changed
packages/medusa/src/api/admin/products/query-config.ts— add lean product configpackages/medusa/src/api/admin/products/middlewares.ts— use lean config for 6 sub-resource routespackages/modules/product/src/services/product-module-service.ts— conditional allVariants loadingImpact
Fixes #14727