Add logs to troubleshoot performances issues

This commit is contained in:
Charles Bochet 2024-09-18 00:10:35 +02:00
parent 7cdf2dc4ec
commit 9c885861a3
3 changed files with 54 additions and 2 deletions

View File

@ -65,8 +65,8 @@ import {
} from './interfaces/pg-graphql.interface';
import { WorkspaceQueryRunnerOptions } from './interfaces/query-runner-option.interface';
import {
computePgGraphQLError,
PgGraphQLConfig,
computePgGraphQLError,
} from './utils/compute-pg-graphql-error.util';
@Injectable()
@ -99,6 +99,9 @@ export class WorkspaceQueryRunnerService {
): Promise<IConnection<Record> | undefined> {
const { authContext, objectMetadataItem } = options;
console.log(
`running findMany for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`,
);
const hookedArgs =
await this.workspaceQueryHookService.executePreQueryHooks(
authContext,
@ -131,6 +134,10 @@ export class WorkspaceQueryRunnerService {
}
const { authContext, objectMetadataItem } = options;
console.log(
`running findOne for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`,
);
const hookedArgs =
await this.workspaceQueryHookService.executePreQueryHooks(
authContext,
@ -168,6 +175,10 @@ export class WorkspaceQueryRunnerService {
const { authContext, objectMetadataItem } = options;
console.log(
`running findDuplicates for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`,
);
const hookedArgs =
await this.workspaceQueryHookService.executePreQueryHooks(
authContext,
@ -222,6 +233,10 @@ export class WorkspaceQueryRunnerService {
): Promise<Record[] | undefined> {
const { authContext, objectMetadataItem } = options;
console.log(
`running createMany for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`,
);
const isQueryRunnerTwentyORMEnabled =
await this.featureFlagService.isFeatureEnabled(
FeatureFlagKey.IsQueryRunnerTwentyORMEnabled,
@ -313,6 +328,9 @@ export class WorkspaceQueryRunnerService {
args: CreateManyResolverArgs<Partial<Record>>,
options: WorkspaceQueryRunnerOptions,
): Promise<Record[] | undefined> {
console.log(
`running upsertMany for ${options.objectMetadataItem.nameSingular} on workspace ${options.authContext.workspace.id}`,
);
const ids = args.data
.map((item) => item.id)
.filter((id) => id !== undefined);
@ -379,6 +397,11 @@ export class WorkspaceQueryRunnerService {
options: WorkspaceQueryRunnerOptions,
): Promise<Record | undefined> {
const { authContext, objectMetadataItem } = options;
console.log(
`running updateOne for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`,
);
const repository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
authContext.workspace.id,
@ -454,6 +477,11 @@ export class WorkspaceQueryRunnerService {
options: WorkspaceQueryRunnerOptions,
): Promise<Record[] | undefined> {
const { authContext, objectMetadataItem } = options;
console.log(
`running updateMany for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`,
);
const repository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
authContext.workspace.id,
@ -549,6 +577,10 @@ export class WorkspaceQueryRunnerService {
): Promise<Record[] | undefined> {
const { authContext, objectMetadataItem } = options;
console.log(
`running deleteMany for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`,
);
assertMutationNotOnRemoteObject(objectMetadataItem);
const maximumRecordAffected = this.environmentService.get(
@ -638,6 +670,10 @@ export class WorkspaceQueryRunnerService {
): Promise<Record[] | undefined> {
const { authContext, objectMetadataItem } = options;
console.log(
`running destroyMany for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`,
);
assertMutationNotOnRemoteObject(objectMetadataItem);
const maximumRecordAffected = this.environmentService.get(
@ -694,6 +730,10 @@ export class WorkspaceQueryRunnerService {
): Promise<Record[] | undefined> {
const { authContext, objectMetadataItem } = options;
console.log(
`running restoreMany for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`,
);
assertMutationNotOnRemoteObject(objectMetadataItem);
const maximumRecordAffected = this.environmentService.get(
@ -765,6 +805,11 @@ export class WorkspaceQueryRunnerService {
options: WorkspaceQueryRunnerOptions,
): Promise<Record | undefined> {
const { authContext, objectMetadataItem } = options;
console.log(
`running deleteOne for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`,
);
const repository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
authContext.workspace.id,

View File

@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import { EntitySchema } from 'typeorm';
@ -16,6 +16,7 @@ import { WorkspaceCacheStorageService } from 'src/engine/workspace-cache-storage
@Injectable()
export class WorkspaceDatasourceFactory {
private readonly logger = new Logger(WorkspaceDatasourceFactory.name);
private cacheManager = new CacheManager<WorkspaceDataSource>();
constructor(
@ -39,6 +40,9 @@ export class WorkspaceDatasourceFactory {
const workspaceDataSource = await this.cacheManager.execute(
`${workspaceId}-${desiredWorkspaceMetadataVersion}`,
async () => {
this.logger.log(
`Creating workspace data source for workspace ${workspaceId} and metadata version ${desiredWorkspaceMetadataVersion}`,
);
const cachedObjectMetadataMap =
await this.workspaceCacheStorageService.getObjectMetadataMap(
workspaceId,

View File

@ -13,6 +13,8 @@ export class CacheManager<T> {
const [workspaceId] = cacheKey.split('-');
if (this.cache.has(cacheKey)) {
console.log('Cache hit for key:', cacheKey);
return this.cache.get(cacheKey)!;
}
@ -23,6 +25,7 @@ export class CacheManager<T> {
}
}
console.log('Cache miss for key:', cacheKey);
const value = await factory();
if (!value) {