diff --git a/api-gateway/src/api/service/schema.ts b/api-gateway/src/api/service/schema.ts index 260af1c840..017a6e9a51 100644 --- a/api-gateway/src/api/service/schema.ts +++ b/api-gateway/src/api/service/schema.ts @@ -795,7 +795,9 @@ export class SchemaApi { const schemas = await guardians.createSchema(newSchema, owner); SchemaHelper.updatePermission(schemas, owner); - await this.cacheService.invalidate(getCacheKey([req.url], user)) + const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`]; + + await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user)) return SchemaUtils.toOld(schemas); } catch (error) { @@ -830,7 +832,8 @@ export class SchemaApi { @HttpCode(HttpStatus.ACCEPTED) async copySchemaAsync( @AuthUser() user: IAuthUser, - @Body() body: any + @Body() body: any, + @Req() req ): Promise { const taskManager = new TaskManager(); const guardians = new Guardians(); @@ -844,6 +847,11 @@ export class SchemaApi { await this.logger.error(error, ['API_GATEWAY']); taskManager.addError(task.taskId, { code: 500, message: error.message }); }); + + const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`]; + + await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user)) + return task; } @@ -884,7 +892,8 @@ export class SchemaApi { async createNewSchemaAsync( @AuthUser() user: IAuthUser, @Param('topicId') topicId: string, - @Body() newSchema: SchemaDTO + @Body() newSchema: SchemaDTO, + @Req() req ): Promise { const owner = new EntityOwner(user); const guardians = new Guardians(); @@ -903,6 +912,11 @@ export class SchemaApi { await this.logger.error(error, ['API_GATEWAY']); taskManager.addError(task.taskId, { code: 500, message: error.message }); }); + + const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`]; + + await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user)) + return task; } @@ -1034,7 +1048,9 @@ export class SchemaApi { const schemas = (await guardians.deleteSchema(schemaId, owner, true) as ISchema[]); SchemaHelper.updatePermission(schemas, owner); - await this.cacheService.invalidate(getCacheKey([req.url], user)) + const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`]; + + await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user)) return SchemaUtils.toOld(schemas); } catch (error) { @@ -1420,7 +1436,8 @@ export class SchemaApi { @AuthUser() user: IAuthUser, @Param('topicId') topicId: string, @Body() body: MessageSchemaDTO, - @Response() res: any + @Response() res: any, + @Req() req ): Promise { const guardians = new Guardians(); const messageId = body?.messageId; @@ -1434,6 +1451,11 @@ export class SchemaApi { category: SchemaCategory.POLICY }, owner); SchemaHelper.updatePermission(items, owner); + + const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`]; + + await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user)) + return res.status(201).header('X-Total-Count', count).send(SchemaUtils.toOld(items)); } catch (error) { await InternalException(error, this.logger); @@ -1485,6 +1507,7 @@ export class SchemaApi { @AuthUser() user: IAuthUser, @Param('topicId') topicId: string, @Body() body: MessageSchemaDTO, + @Req() req ): Promise { const messageId = body?.messageId; if (!messageId) { @@ -1500,6 +1523,11 @@ export class SchemaApi { await this.logger.error(error, ['API_GATEWAY']); taskManager.addError(task.taskId, { code: 500, message: error.message }); }); + + const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`]; + + await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user)) + return task; } @@ -1542,7 +1570,8 @@ export class SchemaApi { @AuthUser() user: IAuthUser, @Param('topicId') topicId: string, @Body() zip: any, - @Response() res: any + @Response() res: any, + @Req() req ): Promise { const guardians = new Guardians(); if (!zip) { @@ -1556,6 +1585,11 @@ export class SchemaApi { category: SchemaCategory.POLICY }, owner); SchemaHelper.updatePermission(items, owner); + + const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`]; + + await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user)) + return res.status(201).header('X-Total-Count', count).send(SchemaUtils.toOld(items)); } catch (error) { await InternalException(error, this.logger); @@ -1599,6 +1633,7 @@ export class SchemaApi { @AuthUser() user: IAuthUser, @Param('topicId') topicId: string, @Body() zip: any, + @Req() req ): Promise { if (!zip) { throw new HttpException('File in body is empty', HttpStatus.UNPROCESSABLE_ENTITY) @@ -1614,6 +1649,11 @@ export class SchemaApi { await this.logger.error(error, ['API_GATEWAY']); taskManager.addError(task.taskId, { code: 500, message: error.message }); }); + + const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`]; + + await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user)) + return task; } @@ -1788,7 +1828,9 @@ export class SchemaApi { SchemaHelper.updateOwner(newSchema, owner); const schema = await guardians.createSystemSchema(newSchema); - await this.cacheService.invalidate(getCacheKey([req.url], req.user)) + const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`]; + + await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user)) return SchemaUtils.toOld(schema); } catch (error) { @@ -1957,6 +1999,7 @@ export class SchemaApi { async deleteSystemSchema( @AuthUser() user: IAuthUser, @Param('schemaId') schemaId: string, + @Req() req ): Promise { try { const guardians = new Guardians(); @@ -1973,6 +2016,10 @@ export class SchemaApi { throw new HttpException('Schema is active.', HttpStatus.UNPROCESSABLE_ENTITY); } await guardians.deleteSchema(schemaId, owner); + + const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`]; + + await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user)) } catch (error) { await InternalException(error, this.logger); } @@ -2246,7 +2293,8 @@ export class SchemaApi { @AuthUser() user: IAuthUser, @Param('topicId') topicId: string, @Body() file: ArrayBuffer, - @Response() res: any + @Response() res: any, + @Req() req ): Promise { if (!file) { throw new HttpException('File in body is empty', HttpStatus.UNPROCESSABLE_ENTITY) @@ -2259,6 +2307,11 @@ export class SchemaApi { category: SchemaCategory.POLICY }, owner); SchemaHelper.updatePermission(items, owner); + + const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`]; + + await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user)) + return res.status(201).header('X-Total-Count', count).send(SchemaUtils.toOld(items)); } catch (error) { await InternalException(error, this.logger); @@ -2305,7 +2358,8 @@ export class SchemaApi { @AuthUser() user: IAuthUser, @Param('topicId') topicId: string, @Body() file: ArrayBuffer, - @Response() res: any + @Response() res: any, + @Req() req ): Promise { if (!file) { throw new HttpException('File in body is empty', HttpStatus.UNPROCESSABLE_ENTITY) @@ -2320,6 +2374,10 @@ export class SchemaApi { await this.logger.error(error, ['API_GATEWAY']); taskManager.addError(task.taskId, { code: 500, message: 'Unknown error: ' + error.message }); }); + const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`]; + + await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user)) + return res.status(202).send(task); }