mirror of
				https://github.com/lingble/twenty.git
				synced 2025-10-31 04:37:56 +00:00 
			
		
		
		
	Add logs to troubleshoot performances issues
This commit is contained in:
		| @@ -65,8 +65,8 @@ import { | |||||||
| } from './interfaces/pg-graphql.interface'; | } from './interfaces/pg-graphql.interface'; | ||||||
| import { WorkspaceQueryRunnerOptions } from './interfaces/query-runner-option.interface'; | import { WorkspaceQueryRunnerOptions } from './interfaces/query-runner-option.interface'; | ||||||
| import { | import { | ||||||
|   computePgGraphQLError, |  | ||||||
|   PgGraphQLConfig, |   PgGraphQLConfig, | ||||||
|  |   computePgGraphQLError, | ||||||
| } from './utils/compute-pg-graphql-error.util'; | } from './utils/compute-pg-graphql-error.util'; | ||||||
|  |  | ||||||
| @Injectable() | @Injectable() | ||||||
| @@ -99,6 +99,9 @@ export class WorkspaceQueryRunnerService { | |||||||
|   ): Promise<IConnection<Record> | undefined> { |   ): Promise<IConnection<Record> | undefined> { | ||||||
|     const { authContext, objectMetadataItem } = options; |     const { authContext, objectMetadataItem } = options; | ||||||
|  |  | ||||||
|  |     console.log( | ||||||
|  |       `running findMany for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`, | ||||||
|  |     ); | ||||||
|     const hookedArgs = |     const hookedArgs = | ||||||
|       await this.workspaceQueryHookService.executePreQueryHooks( |       await this.workspaceQueryHookService.executePreQueryHooks( | ||||||
|         authContext, |         authContext, | ||||||
| @@ -131,6 +134,10 @@ export class WorkspaceQueryRunnerService { | |||||||
|     } |     } | ||||||
|     const { authContext, objectMetadataItem } = options; |     const { authContext, objectMetadataItem } = options; | ||||||
|  |  | ||||||
|  |     console.log( | ||||||
|  |       `running findOne for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`, | ||||||
|  |     ); | ||||||
|  |  | ||||||
|     const hookedArgs = |     const hookedArgs = | ||||||
|       await this.workspaceQueryHookService.executePreQueryHooks( |       await this.workspaceQueryHookService.executePreQueryHooks( | ||||||
|         authContext, |         authContext, | ||||||
| @@ -168,6 +175,10 @@ export class WorkspaceQueryRunnerService { | |||||||
|  |  | ||||||
|     const { authContext, objectMetadataItem } = options; |     const { authContext, objectMetadataItem } = options; | ||||||
|  |  | ||||||
|  |     console.log( | ||||||
|  |       `running findDuplicates for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`, | ||||||
|  |     ); | ||||||
|  |  | ||||||
|     const hookedArgs = |     const hookedArgs = | ||||||
|       await this.workspaceQueryHookService.executePreQueryHooks( |       await this.workspaceQueryHookService.executePreQueryHooks( | ||||||
|         authContext, |         authContext, | ||||||
| @@ -222,6 +233,10 @@ export class WorkspaceQueryRunnerService { | |||||||
|   ): Promise<Record[] | undefined> { |   ): Promise<Record[] | undefined> { | ||||||
|     const { authContext, objectMetadataItem } = options; |     const { authContext, objectMetadataItem } = options; | ||||||
|  |  | ||||||
|  |     console.log( | ||||||
|  |       `running createMany for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`, | ||||||
|  |     ); | ||||||
|  |  | ||||||
|     const isQueryRunnerTwentyORMEnabled = |     const isQueryRunnerTwentyORMEnabled = | ||||||
|       await this.featureFlagService.isFeatureEnabled( |       await this.featureFlagService.isFeatureEnabled( | ||||||
|         FeatureFlagKey.IsQueryRunnerTwentyORMEnabled, |         FeatureFlagKey.IsQueryRunnerTwentyORMEnabled, | ||||||
| @@ -313,6 +328,9 @@ export class WorkspaceQueryRunnerService { | |||||||
|     args: CreateManyResolverArgs<Partial<Record>>, |     args: CreateManyResolverArgs<Partial<Record>>, | ||||||
|     options: WorkspaceQueryRunnerOptions, |     options: WorkspaceQueryRunnerOptions, | ||||||
|   ): Promise<Record[] | undefined> { |   ): Promise<Record[] | undefined> { | ||||||
|  |     console.log( | ||||||
|  |       `running upsertMany for ${options.objectMetadataItem.nameSingular} on workspace ${options.authContext.workspace.id}`, | ||||||
|  |     ); | ||||||
|     const ids = args.data |     const ids = args.data | ||||||
|       .map((item) => item.id) |       .map((item) => item.id) | ||||||
|       .filter((id) => id !== undefined); |       .filter((id) => id !== undefined); | ||||||
| @@ -379,6 +397,11 @@ export class WorkspaceQueryRunnerService { | |||||||
|     options: WorkspaceQueryRunnerOptions, |     options: WorkspaceQueryRunnerOptions, | ||||||
|   ): Promise<Record | undefined> { |   ): Promise<Record | undefined> { | ||||||
|     const { authContext, objectMetadataItem } = options; |     const { authContext, objectMetadataItem } = options; | ||||||
|  |  | ||||||
|  |     console.log( | ||||||
|  |       `running updateOne for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`, | ||||||
|  |     ); | ||||||
|  |  | ||||||
|     const repository = |     const repository = | ||||||
|       await this.twentyORMGlobalManager.getRepositoryForWorkspace( |       await this.twentyORMGlobalManager.getRepositoryForWorkspace( | ||||||
|         authContext.workspace.id, |         authContext.workspace.id, | ||||||
| @@ -454,6 +477,11 @@ export class WorkspaceQueryRunnerService { | |||||||
|     options: WorkspaceQueryRunnerOptions, |     options: WorkspaceQueryRunnerOptions, | ||||||
|   ): Promise<Record[] | undefined> { |   ): Promise<Record[] | undefined> { | ||||||
|     const { authContext, objectMetadataItem } = options; |     const { authContext, objectMetadataItem } = options; | ||||||
|  |  | ||||||
|  |     console.log( | ||||||
|  |       `running updateMany for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`, | ||||||
|  |     ); | ||||||
|  |  | ||||||
|     const repository = |     const repository = | ||||||
|       await this.twentyORMGlobalManager.getRepositoryForWorkspace( |       await this.twentyORMGlobalManager.getRepositoryForWorkspace( | ||||||
|         authContext.workspace.id, |         authContext.workspace.id, | ||||||
| @@ -549,6 +577,10 @@ export class WorkspaceQueryRunnerService { | |||||||
|   ): Promise<Record[] | undefined> { |   ): Promise<Record[] | undefined> { | ||||||
|     const { authContext, objectMetadataItem } = options; |     const { authContext, objectMetadataItem } = options; | ||||||
|  |  | ||||||
|  |     console.log( | ||||||
|  |       `running deleteMany for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`, | ||||||
|  |     ); | ||||||
|  |  | ||||||
|     assertMutationNotOnRemoteObject(objectMetadataItem); |     assertMutationNotOnRemoteObject(objectMetadataItem); | ||||||
|  |  | ||||||
|     const maximumRecordAffected = this.environmentService.get( |     const maximumRecordAffected = this.environmentService.get( | ||||||
| @@ -638,6 +670,10 @@ export class WorkspaceQueryRunnerService { | |||||||
|   ): Promise<Record[] | undefined> { |   ): Promise<Record[] | undefined> { | ||||||
|     const { authContext, objectMetadataItem } = options; |     const { authContext, objectMetadataItem } = options; | ||||||
|  |  | ||||||
|  |     console.log( | ||||||
|  |       `running destroyMany for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`, | ||||||
|  |     ); | ||||||
|  |  | ||||||
|     assertMutationNotOnRemoteObject(objectMetadataItem); |     assertMutationNotOnRemoteObject(objectMetadataItem); | ||||||
|  |  | ||||||
|     const maximumRecordAffected = this.environmentService.get( |     const maximumRecordAffected = this.environmentService.get( | ||||||
| @@ -694,6 +730,10 @@ export class WorkspaceQueryRunnerService { | |||||||
|   ): Promise<Record[] | undefined> { |   ): Promise<Record[] | undefined> { | ||||||
|     const { authContext, objectMetadataItem } = options; |     const { authContext, objectMetadataItem } = options; | ||||||
|  |  | ||||||
|  |     console.log( | ||||||
|  |       `running restoreMany for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`, | ||||||
|  |     ); | ||||||
|  |  | ||||||
|     assertMutationNotOnRemoteObject(objectMetadataItem); |     assertMutationNotOnRemoteObject(objectMetadataItem); | ||||||
|  |  | ||||||
|     const maximumRecordAffected = this.environmentService.get( |     const maximumRecordAffected = this.environmentService.get( | ||||||
| @@ -765,6 +805,11 @@ export class WorkspaceQueryRunnerService { | |||||||
|     options: WorkspaceQueryRunnerOptions, |     options: WorkspaceQueryRunnerOptions, | ||||||
|   ): Promise<Record | undefined> { |   ): Promise<Record | undefined> { | ||||||
|     const { authContext, objectMetadataItem } = options; |     const { authContext, objectMetadataItem } = options; | ||||||
|  |  | ||||||
|  |     console.log( | ||||||
|  |       `running deleteOne for ${objectMetadataItem.nameSingular} on workspace ${authContext.workspace.id}`, | ||||||
|  |     ); | ||||||
|  |  | ||||||
|     const repository = |     const repository = | ||||||
|       await this.twentyORMGlobalManager.getRepositoryForWorkspace( |       await this.twentyORMGlobalManager.getRepositoryForWorkspace( | ||||||
|         authContext.workspace.id, |         authContext.workspace.id, | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| import { Injectable } from '@nestjs/common'; | import { Injectable, Logger } from '@nestjs/common'; | ||||||
|  |  | ||||||
| import { EntitySchema } from 'typeorm'; | import { EntitySchema } from 'typeorm'; | ||||||
|  |  | ||||||
| @@ -16,6 +16,7 @@ import { WorkspaceCacheStorageService } from 'src/engine/workspace-cache-storage | |||||||
|  |  | ||||||
| @Injectable() | @Injectable() | ||||||
| export class WorkspaceDatasourceFactory { | export class WorkspaceDatasourceFactory { | ||||||
|  |   private readonly logger = new Logger(WorkspaceDatasourceFactory.name); | ||||||
|   private cacheManager = new CacheManager<WorkspaceDataSource>(); |   private cacheManager = new CacheManager<WorkspaceDataSource>(); | ||||||
|  |  | ||||||
|   constructor( |   constructor( | ||||||
| @@ -39,6 +40,9 @@ export class WorkspaceDatasourceFactory { | |||||||
|     const workspaceDataSource = await this.cacheManager.execute( |     const workspaceDataSource = await this.cacheManager.execute( | ||||||
|       `${workspaceId}-${desiredWorkspaceMetadataVersion}`, |       `${workspaceId}-${desiredWorkspaceMetadataVersion}`, | ||||||
|       async () => { |       async () => { | ||||||
|  |         this.logger.log( | ||||||
|  |           `Creating workspace data source for workspace ${workspaceId} and metadata version ${desiredWorkspaceMetadataVersion}`, | ||||||
|  |         ); | ||||||
|         const cachedObjectMetadataMap = |         const cachedObjectMetadataMap = | ||||||
|           await this.workspaceCacheStorageService.getObjectMetadataMap( |           await this.workspaceCacheStorageService.getObjectMetadataMap( | ||||||
|             workspaceId, |             workspaceId, | ||||||
|   | |||||||
| @@ -13,6 +13,8 @@ export class CacheManager<T> { | |||||||
|     const [workspaceId] = cacheKey.split('-'); |     const [workspaceId] = cacheKey.split('-'); | ||||||
|  |  | ||||||
|     if (this.cache.has(cacheKey)) { |     if (this.cache.has(cacheKey)) { | ||||||
|  |       console.log('Cache hit for key:', cacheKey); | ||||||
|  |  | ||||||
|       return this.cache.get(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(); |     const value = await factory(); | ||||||
|  |  | ||||||
|     if (!value) { |     if (!value) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Charles Bochet
					Charles Bochet