Improve performances (#14869)
## Improvements - Add logs to all gql operations and rest calls to help debug CPU issues on the backend. These are temporary and should be removed - Remove nested relations from workflowVersions load (used to add manual triggers in the side bar). On some workspaces this call result in a response of 4MB which is heavy on CPU - Investigated Redis Usage ==> made a few improvements, we are should still migrate to the new cache service once available - investigated db calls in messaging / calendar fetch list + workflow enqueue run cron jobs. Everything seems to be properly batched
This commit is contained in:
+15
-3
@@ -43,14 +43,20 @@ export function useCachedMetadata(config: CacheMetadataPluginConfig): Plugin {
|
||||
|
||||
return {
|
||||
onRequest: async ({ endResponse, serverContext }) => {
|
||||
// TODO: we should probably override the graphql-yoga request type to include the workspace and locale
|
||||
const request = (serverContext as unknown as { req: Request }).req;
|
||||
|
||||
if (!request.workspace?.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!config.operationsToCache.includes(getOperationName(serverContext))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cacheKey = computeCacheKey({
|
||||
operationName: getOperationName(serverContext),
|
||||
// TODO: we should probably override the graphql-yoga request type to include the workspace and locale
|
||||
request: (serverContext as unknown as { req: Request }).req,
|
||||
request,
|
||||
});
|
||||
const cachedResponse = await config.cacheGetter(cacheKey);
|
||||
|
||||
@@ -61,13 +67,19 @@ export function useCachedMetadata(config: CacheMetadataPluginConfig): Plugin {
|
||||
}
|
||||
},
|
||||
onResponse: async ({ response, serverContext }) => {
|
||||
const request = (serverContext as unknown as { req: Request }).req;
|
||||
|
||||
if (!request.workspace?.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!config.operationsToCache.includes(getOperationName(serverContext))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cacheKey = computeCacheKey({
|
||||
operationName: getOperationName(serverContext),
|
||||
request: (serverContext as unknown as { req: Request }).req,
|
||||
request,
|
||||
});
|
||||
|
||||
const cachedResponse = await config.cacheGetter(cacheKey);
|
||||
|
||||
+23
@@ -2,6 +2,7 @@ import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Logger,
|
||||
Patch,
|
||||
Post,
|
||||
Put,
|
||||
@@ -22,10 +23,14 @@ import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
||||
@UseGuards(JwtAuthGuard, WorkspaceAuthGuard)
|
||||
@UseFilters(RestApiExceptionFilter)
|
||||
export class RestApiCoreController {
|
||||
private readonly logger = new Logger(RestApiCoreController.name);
|
||||
constructor(private readonly restApiCoreService: RestApiCoreService) {}
|
||||
|
||||
@Post('batch/*')
|
||||
async handleApiPostBatch(@Req() request: Request, @Res() res: Response) {
|
||||
this.logger.log(
|
||||
`[REST API] Processing BATCH request to ${request.path} on workspace ${request.workspaceId}`,
|
||||
);
|
||||
const result = await this.restApiCoreService.createMany(request);
|
||||
|
||||
res.status(201).send(result);
|
||||
@@ -33,6 +38,9 @@ export class RestApiCoreController {
|
||||
|
||||
@Post('*/duplicates')
|
||||
async handleApiFindDuplicates(@Req() request: Request, @Res() res: Response) {
|
||||
this.logger.log(
|
||||
`[REST API] Processing DUPLICATES request to ${request.path} on workspace ${request.workspaceId}`,
|
||||
);
|
||||
const result = await this.restApiCoreService.findDuplicates(request);
|
||||
|
||||
res.status(200).send(result);
|
||||
@@ -40,6 +48,9 @@ export class RestApiCoreController {
|
||||
|
||||
@Post('*')
|
||||
async handleApiPost(@Req() request: Request, @Res() res: Response) {
|
||||
this.logger.log(
|
||||
`[REST API] Processing POST request to ${request.path} on workspace ${request.workspaceId}`,
|
||||
);
|
||||
const result = await this.restApiCoreService.createOne(request);
|
||||
|
||||
res.status(201).send(result);
|
||||
@@ -47,6 +58,9 @@ export class RestApiCoreController {
|
||||
|
||||
@Get('*')
|
||||
async handleApiGet(@Req() request: Request, @Res() res: Response) {
|
||||
this.logger.log(
|
||||
`[REST API] Processing GET request to ${request.path} on workspace ${request.workspaceId}`,
|
||||
);
|
||||
const result = await this.restApiCoreService.get(request);
|
||||
|
||||
res.status(200).send(result);
|
||||
@@ -54,6 +68,9 @@ export class RestApiCoreController {
|
||||
|
||||
@Delete('*')
|
||||
async handleApiDelete(@Req() request: Request, @Res() res: Response) {
|
||||
this.logger.log(
|
||||
`[REST API] Processing DELETE request to ${request.path} on workspace ${request.workspaceId}`,
|
||||
);
|
||||
const result = await this.restApiCoreService.delete(request);
|
||||
|
||||
res.status(200).send(result);
|
||||
@@ -61,6 +78,9 @@ export class RestApiCoreController {
|
||||
|
||||
@Patch('*')
|
||||
async handleApiPatch(@Req() request: Request, @Res() res: Response) {
|
||||
this.logger.log(
|
||||
`[REST API] Processing PATCH request to ${request.path} on workspace ${request.workspaceId}`,
|
||||
);
|
||||
const result = await this.restApiCoreService.update(request);
|
||||
|
||||
res.status(200).send(result);
|
||||
@@ -71,6 +91,9 @@ export class RestApiCoreController {
|
||||
// of PATCH, and because the PUT verb is often used as a PATCH.
|
||||
@Put('*')
|
||||
async handleApiPut(@Req() request: Request, @Res() res: Response) {
|
||||
this.logger.log(
|
||||
`[REST API] Processing PUT request to ${request.path} on workspace ${request.workspaceId}`,
|
||||
);
|
||||
const result = await this.restApiCoreService.update(request);
|
||||
|
||||
res.status(200).send(result);
|
||||
|
||||
Reference in New Issue
Block a user