fix: Better logging and revie system of debug

This commit is contained in:
Julien Froidefond
2025-02-23 22:19:24 +01:00
parent c7b2621946
commit 66e1db7788
11 changed files with 70 additions and 110 deletions

View File

@@ -7,9 +7,8 @@ export function withPageTiming(pageName: string, Component: PageComponent) {
const start = performance.now();
const result = await Promise.resolve(Component(props));
const duration = performance.now() - start;
// Log le temps de rendu
await DebugService.logPageRender(pageName, duration);
await DebugService.logPageRender(pageName + JSON.stringify(props.params), duration);
return result;
};

View File

@@ -53,34 +53,12 @@ export abstract class BaseApiService {
type: CacheType = "DEFAULT"
): Promise<T> {
const cacheService = await getServerCacheService();
const startTime = performance.now();
try {
const result = await cacheService.getOrSet(key, fetcher, type);
const endTime = performance.now();
// Log la requête avec l'indication du cache
await DebugService.logRequest({
url: key,
startTime,
endTime,
fromCache: true,
cacheType: type,
});
return result;
} catch (error) {
const endTime = performance.now();
// Log aussi les erreurs
await DebugService.logRequest({
url: key,
startTime,
endTime,
fromCache: true,
cacheType: type,
});
throw error;
}
}

View File

@@ -1,6 +1,7 @@
import fs from "fs";
import path from "path";
import { PreferencesService } from "./preferences.service";
import { DebugService } from "./debug.service";
type CacheMode = "file" | "memory";
@@ -370,13 +371,26 @@ class ServerCacheService {
fetcher: () => Promise<T>,
type: keyof typeof ServerCacheService.DEFAULT_TTL = "DEFAULT"
): Promise<T> {
const startTime = performance.now();
const cached = this.get(key);
if (cached !== null) {
const endTime = performance.now();
// Log la requête avec l'indication du cache
await DebugService.logRequest({
url: key,
startTime,
endTime,
fromCache: true,
cacheType: type,
});
return cached as T;
}
try {
const data = await fetcher();
this.set(key, data, type);
return data;
} catch (error) {