From f4101b7a07f69336990025269fee3ba155fda07c Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Wed, 22 Apr 2020 13:54:21 +0200 Subject: [PATCH] fix(core): Correctly invalidate Zone cache on Country changes --- .../e2e/graphql/generated-e2e-admin-types.ts | 34 +++++++++---------- .../src/service/services/country.service.ts | 6 ++++ .../core/src/service/services/zone.service.ts | 6 +++- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/packages/core/e2e/graphql/generated-e2e-admin-types.ts b/packages/core/e2e/graphql/generated-e2e-admin-types.ts index 8c4235ee16..eb71d69f06 100644 --- a/packages/core/e2e/graphql/generated-e2e-admin-types.ts +++ b/packages/core/e2e/graphql/generated-e2e-admin-types.ts @@ -3605,17 +3605,6 @@ export type GetChannelsQuery = { __typename?: 'Query' } & { channels: Array<{ __typename?: 'Channel' } & Pick>; }; -export type UpdateChannelMutationVariables = { - input: UpdateChannelInput; -}; - -export type UpdateChannelMutation = { __typename?: 'Mutation' } & { - updateChannel: { __typename?: 'Channel' } & Pick< - Channel, - 'id' | 'code' | 'defaultLanguageCode' | 'currencyCode' - >; -}; - export type DeleteChannelMutationVariables = { id: Scalars['ID']; }; @@ -4714,6 +4703,17 @@ export type DeleteAssetMutation = { __typename?: 'Mutation' } & { deleteAsset: { __typename?: 'DeletionResponse' } & Pick; }; +export type UpdateChannelMutationVariables = { + input: UpdateChannelInput; +}; + +export type UpdateChannelMutation = { __typename?: 'Mutation' } & { + updateChannel: { __typename?: 'Channel' } & Pick< + Channel, + 'id' | 'code' | 'defaultLanguageCode' | 'currencyCode' + >; +}; + export type UpdateOptionGroupMutationVariables = { input: UpdateProductOptionGroupInput; }; @@ -5505,12 +5505,6 @@ export namespace GetChannels { export type Channels = NonNullable; } -export namespace UpdateChannel { - export type Variables = UpdateChannelMutationVariables; - export type Mutation = UpdateChannelMutation; - export type UpdateChannel = UpdateChannelMutation['updateChannel']; -} - export namespace DeleteChannel { export type Variables = DeleteChannelMutationVariables; export type Mutation = DeleteChannelMutation; @@ -6236,6 +6230,12 @@ export namespace DeleteAsset { export type DeleteAsset = DeleteAssetMutation['deleteAsset']; } +export namespace UpdateChannel { + export type Variables = UpdateChannelMutationVariables; + export type Mutation = UpdateChannelMutation; + export type UpdateChannel = UpdateChannelMutation['updateChannel']; +} + export namespace UpdateOptionGroup { export type Variables = UpdateOptionGroupMutationVariables; export type Mutation = UpdateOptionGroupMutation; diff --git a/packages/core/src/service/services/country.service.ts b/packages/core/src/service/services/country.service.ts index ba89ff491c..ef7bd7da6e 100644 --- a/packages/core/src/service/services/country.service.ts +++ b/packages/core/src/service/services/country.service.ts @@ -22,12 +22,15 @@ import { TranslatableSaver } from '../helpers/translatable-saver/translatable-sa import { getEntityOrThrow } from '../helpers/utils/get-entity-or-throw'; import { translateDeep } from '../helpers/utils/translate-entity'; +import { ZoneService } from './zone.service'; + @Injectable() export class CountryService { constructor( @InjectConnection() private connection: Connection, private listQueryBuilder: ListQueryBuilder, private translatableSaver: TranslatableSaver, + private zoneService: ZoneService, ) {} findAll( @@ -71,6 +74,7 @@ export class CountryService { entityType: Country, translationType: CountryTranslation, }); + await this.zoneService.updateZonesCache(); return assertFound(this.findOne(ctx, country.id)); } @@ -80,6 +84,7 @@ export class CountryService { entityType: Country, translationType: CountryTranslation, }); + await this.zoneService.updateZonesCache(); return assertFound(this.findOne(ctx, country.id)); } @@ -97,6 +102,7 @@ export class CountryService { message: ctx.translate('message.country-used-in-addresses', { count: addressesUsingCountry }), }; } else { + await this.zoneService.updateZonesCache(); await this.connection.getRepository(Country).remove(country); return { result: DeletionResult.DELETED, diff --git a/packages/core/src/service/services/zone.service.ts b/packages/core/src/service/services/zone.service.ts index dd9b677284..f663709d0b 100644 --- a/packages/core/src/service/services/zone.service.ts +++ b/packages/core/src/service/services/zone.service.ts @@ -139,7 +139,11 @@ export class ZoneService implements OnModuleInit { return this.connection.getRepository(Country).findByIds(ids); } - private async updateZonesCache() { + /** + * TODO: This is not good for multi-instance deployments. A better solution will + * need to be found without adversely affecting performance. + */ + async updateZonesCache() { this.zones = await this.connection.getRepository(Zone).find({ relations: ['members'], });