Skip to content

Commit

Permalink
fix(core): Correctly invalidate Zone cache on Country changes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Apr 22, 2020
1 parent 821f258 commit f4101b7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
34 changes: 17 additions & 17 deletions packages/core/e2e/graphql/generated-e2e-admin-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3605,17 +3605,6 @@ export type GetChannelsQuery = { __typename?: 'Query' } & {
channels: Array<{ __typename?: 'Channel' } & Pick<Channel, 'id' | 'code' | 'token'>>;
};

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'];
};
Expand Down Expand Up @@ -4714,6 +4703,17 @@ export type DeleteAssetMutation = { __typename?: 'Mutation' } & {
deleteAsset: { __typename?: 'DeletionResponse' } & Pick<DeletionResponse, 'result' | 'message'>;
};

export type UpdateChannelMutationVariables = {
input: UpdateChannelInput;
};

export type UpdateChannelMutation = { __typename?: 'Mutation' } & {
updateChannel: { __typename?: 'Channel' } & Pick<
Channel,
'id' | 'code' | 'defaultLanguageCode' | 'currencyCode'
>;
};

export type UpdateOptionGroupMutationVariables = {
input: UpdateProductOptionGroupInput;
};
Expand Down Expand Up @@ -5505,12 +5505,6 @@ export namespace GetChannels {
export type Channels = NonNullable<GetChannelsQuery['channels'][0]>;
}

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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/service/services/country.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -71,6 +74,7 @@ export class CountryService {
entityType: Country,
translationType: CountryTranslation,
});
await this.zoneService.updateZonesCache();
return assertFound(this.findOne(ctx, country.id));
}

Expand All @@ -80,6 +84,7 @@ export class CountryService {
entityType: Country,
translationType: CountryTranslation,
});
await this.zoneService.updateZonesCache();
return assertFound(this.findOne(ctx, country.id));
}

Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/service/services/zone.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
});
Expand Down

0 comments on commit f4101b7

Please sign in to comment.