Browse Source

perf(core): Use request cache for hot-path tax rate calculation

Michael Bromley 4 years ago
parent
commit
9e22e8be58
1 changed files with 3 additions and 3 deletions
  1. 3 3
      packages/core/src/service/services/product-variant.service.ts

+ 3 - 3
packages/core/src/service/services/product-variant.service.ts

@@ -592,10 +592,10 @@ export class ProductVariantService {
         if (!activeTaxZone) {
             throw new InternalServerError(`error.no-active-tax-zone`);
         }
-        const applicableTaxRate = await this.taxRateService.getApplicableTaxRate(
+        const applicableTaxRate = await this.requestCache.get(
             ctx,
-            activeTaxZone,
-            variant.taxCategory,
+            `applicableTaxRate-${activeTaxZone.id}-${variant.taxCategory.id}`,
+            () => this.taxRateService.getApplicableTaxRate(ctx, activeTaxZone, variant.taxCategory),
         );
 
         const { productVariantPriceCalculationStrategy } = this.configService.catalogOptions;