Browse Source

refactor(core): Remove unused promotions cache property

Relates to #988
Michael Bromley 4 years ago
parent
commit
c5ba7357a6
1 changed files with 0 additions and 27 deletions
  1. 0 27
      packages/core/src/service/services/promotion.service.ts

+ 0 - 27
packages/core/src/service/services/promotion.service.ts

@@ -44,12 +44,6 @@ import { ChannelService } from './channel.service';
 export class PromotionService {
     availableConditions: PromotionCondition[] = [];
     availableActions: PromotionAction[] = [];
-    /**
-     * All active AdjustmentSources are cached in memory becuase they are needed
-     * every time an order is changed, which will happen often. Caching them means
-     * a DB call is not required newly each time.
-     */
-    private activePromotions: Promotion[] = [];
 
     constructor(
         private connection: TransactionalConnection,
@@ -91,16 +85,6 @@ export class PromotionService {
         return this.availableActions.map(x => x.toGraphQlType(ctx));
     }
 
-    /**
-     * Returns all active AdjustmentSources.
-     */
-    async getActivePromotions(): Promise<Promotion[]> {
-        if (!this.activePromotions.length) {
-            await this.updatePromotions();
-        }
-        return this.activePromotions;
-    }
-
     async createPromotion(
         ctx: RequestContext,
         input: CreatePromotionInput,
@@ -126,7 +110,6 @@ export class PromotionService {
         }
         this.channelService.assignToCurrentChannel(promotion, ctx);
         const newPromotion = await this.connection.getRepository(ctx, Promotion).save(promotion);
-        await this.updatePromotions();
         return assertFound(this.findOne(ctx, newPromotion.id));
     }
 
@@ -153,7 +136,6 @@ export class PromotionService {
         }
         promotion.priorityScore = this.calculatePriorityScore(input);
         await this.connection.getRepository(ctx, Promotion).save(updatedPromotion, { reload: false });
-        await this.updatePromotions();
         return assertFound(this.findOne(ctx, updatedPromotion.id));
     }
 
@@ -266,15 +248,6 @@ export class PromotionService {
         return [...conditions, ...actions].reduce((score, op) => score + op.priorityValue, 0);
     }
 
-    /**
-     * Update the activeSources cache.
-     */
-    private async updatePromotions() {
-        this.activePromotions = await this.connection.getRepository(Promotion).find({
-            where: { enabled: true },
-        });
-    }
-
     private validateRequiredConditions(
         conditions: ConfigurableOperation[],
         actions: ConfigurableOperation[],