Skip to content

Commit

Permalink
refactor(core): Remove unused promotions cache property
Browse files Browse the repository at this point in the history
Relates to #988
  • Loading branch information
michaelbromley committed Sep 27, 2021
1 parent aed08dd commit c5ba735
Showing 1 changed file with 0 additions and 27 deletions.
27 changes: 0 additions & 27 deletions packages/core/src/service/services/promotion.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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));
}

Expand All @@ -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));
}

Expand Down Expand Up @@ -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[],
Expand Down

0 comments on commit c5ba735

Please sign in to comment.