Repository navigation
Conversation
brmk
force-pushed
the
perf/stock-levels-resolver-batch
branch
from
September 10, 2026 14:43
b6b2923 to
c7fe51e
Compare
The Admin API `ProductVariant.stockLevels` field ran one channel-filtered query per variant, so a list page of 34 variants cost 34 stock queries. vendurehq#5224 batched the sibling `getAvailableStock` path but left this one alone. `getStockLevelsForVariant` now reads through a per-request DataLoader with `cache: false`, as in vendurehq#5224: same joins and channel filter, `IN (...)` in place of `= :id`, rows grouped by variant. The batch orders by `stockLocationId`, which the per-variant query returned implicitly and the multi-location e2e suite relies on. Same 34-variant page: 34 stock queries → 1. Relates to vendurehq#5224
brmk
force-pushed
the
perf/stock-levels-resolver-batch
branch
from
September 10, 2026 19:39
c7fe51e to
8129c3a
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.
Description
The Admin API
ProductVariant.stockLevelsfield resolves one channel-filtered query per variant, so every variant list page in the dashboard costs one stock query per row. vendurehq#5224 batched the sibling path behindgetAvailableStock(stockOnHand/stockAllocated) but did not touchstockLevels.getStockLevelsForVariantnow reads through a per-requestDataLoaderheld inRequestContextCacheService, the same mechanism as vendurehq#5224. The batch runs the same joins and channel filter withproductVariantId IN (...)and groups the rows by variant. The loader lives on the ctx that supplies the channel filter, so it cannot mix channels.cache: falsebatches without memoizing, so a write earlier in the request is not masked. Public signature unchanged.The batch orders by
stockLocationId. The single-variant query returned that order implicitly through the unique(productVariantId, stockLocationId)index, and the multi-location e2e suite asserts on it; anIN (...)query does not guarantee it.Measured with a counting TypeORM logger on the core e2e fixture,
productVariants(options: { take: 40 })withstockLevelsselected: 34 stock queries → 1, on sqljs, Postgres 16, MySQL 8 and MariaDB 11.5. Thestock-control,stock-control-multi-locationandstock-locatione2e suites pass unchanged on all four. Seven unit cases added tostock-level.service.spec.ts.Relates to vendurehq#5224
Breaking changes
None. No schema, GraphQL or config change.
Checklist
📌 Always:
👍 Most of the time: