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

@ -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) {