Skip to content

Commit

Permalink
Feature/cache new routes (#3950)
Browse files Browse the repository at this point in the history
* feat: move helper logger from winston to pino[3834]

* [skip ci] Add swagger.yaml

* feat: provide logger for services across di[3834]

* fix: remove winston dependencies[3834]

* feat: add tranports and factory for pino logger (#3877)

Co-authored-by: Ihar <[email protected]>

* feat: dividing code base on modules and refactore[3834]

* feat: seq transport for pino logger[3834]

* feat: move ai srvice to pino logger[3834]

* feat: move auth service to pino[3834]

* feat: move gardian service to pino logger[3834]

* fix: api gate way internal error func and web sockets[3834]

* feat: move notification service to pino[3834]

* feat: move policy service to pino logger[3834]

* feat: move queue service to pino logger[3834]

* feat: move worker service to pino logger[3834]

* feat: mongo logger init and pino logger init[3834]

* feat: pino logger in common helpers for guardian service[3834]

* feat: pino logger instead new old logger for policy service[3834]

* feat: move to pino analitics-sevice[3834]

* refactore code[3834]

* refactore code[3834]

* fix: env for common config for pino logger[3834]

* fix: linter issues[3834]

* docs: link to the seq logging documentation[3834]

* feat: conditionat for mongo transport and refactore code[3834]

* feat: subscribtions on frontent for states logger service[3834] (#3922)

* feat: subscribtions on frontent for states logger service[3834]

* feat: open tab with seq by click button[3834]

* [skip ci] Add swagger.yaml

---------

Co-authored-by: Ihar <[email protected]>
Co-authored-by: envision-ci-agent <[email protected]>

* fix: configs api-gateway[3834]

* feat: api key for seq and refactor code

* feat: add policy groups and navigation cache and invalidation

* feat: add cache and invalidation for contracts api

* feat: add cache and invalidation for schemas api

* feat: add cache and invalidation for tags api

* refactore code

* feat: add cache and invalidation for modules api

* feat: add cache and invalidation for ipfs api

* fix: remove is express veriable from cache

* refactore code

* refactore code

* [skip ci] Add swagger.yaml

* fix:add additional invalidation for wipe retire

* fix:add additional invalidation for retire requests

* fix:add additional invalidation for retire pools

* Revert "fix:add additional invalidation for retire pools"

This reverts commit 0211cbc.

* Revert "fix:add additional invalidation for retire requests"

This reverts commit 358609e.

* Revert "feat: add cache and invalidation for contracts api"

This reverts commit 942ae73.

* feat: possible work with buffer in cache

* [skip ci] Add swagger.yaml

---------

Co-authored-by: Ihar <[email protected]>
Co-authored-by: envision-ci-agent <[email protected]>
  • Loading branch information
3 people authored Aug 15, 2024
1 parent 1e72ce6 commit aacfc1f
Show file tree
Hide file tree
Showing 13 changed files with 319 additions and 71 deletions.
2 changes: 0 additions & 2 deletions api-gateway/src/api/service/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ export class AccountApi {
type: InternalServerErrorDTO,
})
@ApiExtraModels(AccountsResponseDTO, InternalServerErrorDTO)
// @UseCache()
@HttpCode(HttpStatus.OK)
async getStandardRegistries(): Promise<any> {
try {
Expand Down Expand Up @@ -299,7 +298,6 @@ export class AccountApi {
type: InternalServerErrorDTO,
})
@ApiExtraModels(AggregatedDTOItem, InternalServerErrorDTO)
// @UseCache()
@HttpCode(HttpStatus.OK)
async getAggregatedStandardRegistries(): Promise<any> {
const engineService = new PolicyEngine();
Expand Down
15 changes: 11 additions & 4 deletions api-gateway/src/api/service/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ export class ContractsApi {
description: 'Internal server error.',
type: InternalServerErrorDTO,
})
// @UseCache({ isExpress: true })
@ApiExtraModels(ContractDTO, InternalServerErrorDTO)
@HttpCode(HttpStatus.OK)
async getWipeRequests(
Expand Down Expand Up @@ -893,6 +892,7 @@ export class ContractsApi {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();

return await guardians.syncRetirePools(owner, contractId);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -942,7 +942,6 @@ export class ContractsApi {
type: InternalServerErrorDTO,
})
@ApiExtraModels(RetireRequestDTO, InternalServerErrorDTO)
// @UseCache({ isExpress: true })
@HttpCode(HttpStatus.OK)
async getRetireRequests(
@AuthUser() user: IAuthUser,
Expand Down Expand Up @@ -1015,7 +1014,6 @@ export class ContractsApi {
type: InternalServerErrorDTO,
})
@ApiExtraModels(RetirePoolDTO, InternalServerErrorDTO)
// @UseCache({ isExpress: true })
@HttpCode(HttpStatus.OK)
async getRetirePools(
@AuthUser() user: IAuthUser,
Expand Down Expand Up @@ -1077,6 +1075,7 @@ export class ContractsApi {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();

return await guardians.clearRetireRequests(owner, contractId);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -1119,6 +1118,7 @@ export class ContractsApi {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();

return await guardians.clearRetirePools(owner, contractId);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -1165,6 +1165,7 @@ export class ContractsApi {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();

return await guardians.setRetirePool(owner, contractId, body);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -1207,6 +1208,7 @@ export class ContractsApi {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();

return await guardians.unsetRetirePool(owner, poolId);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -1249,6 +1251,7 @@ export class ContractsApi {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();

return await guardians.unsetRetireRequest(owner, requestId);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -1296,6 +1299,7 @@ export class ContractsApi {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();

return await guardians.retire(owner, poolId, body);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -1338,6 +1342,7 @@ export class ContractsApi {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();

return await guardians.approveRetire(owner, requestId);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -1381,6 +1386,7 @@ export class ContractsApi {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();

return await guardians.cancelRetire(owner, requestId);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -1431,6 +1437,7 @@ export class ContractsApi {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();

return await guardians.addRetireAdmin(owner, contractId, hederaId);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -1481,6 +1488,7 @@ export class ContractsApi {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();

return await guardians.removeRetireAdmin(owner, contractId, hederaId);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -1529,7 +1537,6 @@ export class ContractsApi {
type: InternalServerErrorDTO,
})
@ApiExtraModels(RetirePoolDTO, InternalServerErrorDTO)
// @UseCache({ isExpress: true })
@HttpCode(HttpStatus.OK)
async getRetireVCs(
@AuthUser() user: IAuthUser,
Expand Down
1 change: 0 additions & 1 deletion api-gateway/src/api/service/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class DemoApi {
type: InternalServerErrorDTO
})
@ApiExtraModels(RegisteredUsersDTO, InternalServerErrorDTO)
// @UseCache()
@HttpCode(HttpStatus.OK)
async registeredUsers(): Promise<RegisteredUsersDTO> {
const users = new Users();
Expand Down
29 changes: 22 additions & 7 deletions api-gateway/src/api/service/ipfs.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Body, Controller, Get, HttpCode, HttpException, HttpStatus, Param, Post, StreamableFile } from '@nestjs/common';
import { Body, Controller, Get, HttpCode, HttpException, HttpStatus, Param, Post, Req, StreamableFile } from '@nestjs/common';
import { ApiBody, ApiExtraModels, ApiInternalServerErrorResponse, ApiOkResponse, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
import { Permissions } from '@guardian/interfaces';
import { Auth } from '#auth';
import { Examples, InternalServerErrorDTO } from '#middlewares';
import { Guardians, InternalException } from '#helpers';
import { CacheService, getCacheKey, Guardians, InternalException, UseCache } from '#helpers';
import { PinoLogger } from '@guardian/common';
import { CACHE, PREFIXES } from '#constants';

@Controller('ipfs')
@ApiTags('ipfs')
export class IpfsApi {
constructor(private readonly logger: PinoLogger) {
constructor(private readonly cacheService: CacheService, private readonly logger: PinoLogger) {
}

/**
Expand Down Expand Up @@ -41,7 +42,8 @@ export class IpfsApi {
@ApiExtraModels(InternalServerErrorDTO)
@HttpCode(HttpStatus.CREATED)
async postFile(
@Body() body: any
@Body() body: any,
@Req() req
): Promise<string> {
try {
if (!Object.values(body).length) {
Expand All @@ -54,6 +56,12 @@ export class IpfsApi {
throw new HttpException('File is not uploaded', HttpStatus.BAD_REQUEST);
}

const invalidedCacheTags = [
`${PREFIXES.IPFS}file/${cid}`,
`${PREFIXES.IPFS}file/${cid}/dry-run`,
];
await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheTags], req.user));

return JSON.stringify(cid);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -97,7 +105,8 @@ export class IpfsApi {
@HttpCode(HttpStatus.CREATED)
async postFileDryRun(
@Param('policyId') policyId: string,
@Body() body: any
@Body() body: any,
@Req() req
): Promise<string> {
try {
if (!Object.values(body).length) {
Expand All @@ -107,6 +116,12 @@ export class IpfsApi {
const guardians = new Guardians();
const { cid } = await guardians.addFileToDryRunStorage(body, policyId);

const invalidedCacheTags = [
`${PREFIXES.IPFS}file/${cid}`,
`${PREFIXES.IPFS}file/${cid}/dry-run`,
];
await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheTags], req.user));

return JSON.stringify(cid);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -145,7 +160,7 @@ export class IpfsApi {
type: InternalServerErrorDTO
})
@ApiExtraModels(InternalServerErrorDTO)
// @UseCache({ ttl: CACHE.LONG_TTL })
@UseCache({ ttl: CACHE.LONG_TTL })
@HttpCode(HttpStatus.OK)
async getFile(
@Param('cid') cid: string
Expand Down Expand Up @@ -194,7 +209,7 @@ export class IpfsApi {
type: InternalServerErrorDTO
})
@ApiExtraModels(InternalServerErrorDTO)
// @UseCache({ ttl: CACHE.LONG_TTL })
@UseCache({ ttl: CACHE.LONG_TTL })
@HttpCode(HttpStatus.OK)
async getFileDryRun(
@Param('cid') cid: string
Expand Down
Loading

0 comments on commit aacfc1f

Please sign in to comment.