Skip to content

Commit

Permalink
perf(core): Use per-request caching for hot ProductVariant paths
Browse files Browse the repository at this point in the history
Relates to #988
  • Loading branch information
michaelbromley committed Sep 27, 2021
1 parent c5ba735 commit 214b86b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/core/src/service/services/product-variant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,12 @@ export class ProductVariantService {
* for purchase by Customers.
*/
async getSaleableStockLevel(ctx: RequestContext, variant: ProductVariant): Promise<number> {
// TODO: Use caching (RequestContextCacheService) to reduce DB calls
const { outOfStockThreshold, trackInventory } = await this.globalSettingsService.getSettings(ctx);
const { outOfStockThreshold, trackInventory } = await this.requestCache.get(
ctx,
'globalSettings',
() => this.globalSettingsService.getSettings(ctx),
);

const inventoryNotTracked =
variant.trackInventory === GlobalFlag.FALSE ||
(variant.trackInventory === GlobalFlag.INHERIT && trackInventory === false);
Expand Down Expand Up @@ -581,7 +585,7 @@ export class ProductVariantService {
});
}
const { taxZoneStrategy } = this.configService.taxOptions;
const zones = this.zoneService.findAll(ctx);
const zones = this.requestCache.get(ctx, 'allZones', () => this.zoneService.findAll(ctx));
const activeTaxZone = await this.requestCache.get(ctx, 'activeTaxZone', () =>
taxZoneStrategy.determineTaxZone(ctx, zones, ctx.channel, order),
);
Expand Down

0 comments on commit 214b86b

Please sign in to comment.