mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-25 03:42:30 +00:00
Put back logs (#2919)
This commit is contained in:
+11
-3
@@ -129,7 +129,7 @@ export function cache<Args extends any[], Result>(
|
||||
async (key: string, signal: AbortSignal | undefined, span: TraceSpan, ...args: Args) => {
|
||||
const timeStart = now();
|
||||
let readCacheDuration = 0;
|
||||
let _fetchDuration = 0;
|
||||
let fetchDuration = 0;
|
||||
|
||||
let result: readonly [CacheEntry, string] | null = null;
|
||||
const tag = cacheDef.tag?.(...args);
|
||||
@@ -179,7 +179,7 @@ export function cache<Args extends any[], Result>(
|
||||
const upstream = await revalidate(key, fallbackOps.signal, ...args);
|
||||
|
||||
readCacheDuration = timeFetch - timeStart;
|
||||
_fetchDuration = now() - timeFetch;
|
||||
fetchDuration = now() - timeFetch;
|
||||
return [upstream, 'fetch'] as const;
|
||||
},
|
||||
|
||||
@@ -219,10 +219,18 @@ export function cache<Args extends any[], Result>(
|
||||
);
|
||||
}
|
||||
|
||||
const _totalDuration = now() - timeStart;
|
||||
const totalDuration = now() - timeStart;
|
||||
|
||||
// Log
|
||||
if (process.env.SILENT !== 'true') {
|
||||
// biome-ignore lint/suspicious/noConsole: we want to log here
|
||||
console.log(
|
||||
`cache: ${key} ${cacheStatus}${
|
||||
cacheStatus === 'hit' ? ` on ${backendName}` : ''
|
||||
} in total ${totalDuration.toFixed(0)}ms, fetch in ${fetchDuration.toFixed(
|
||||
0
|
||||
)}ms, read in ${readCacheDuration.toFixed(0)}ms`
|
||||
);
|
||||
}
|
||||
|
||||
if (savedEntry.meta.revalidatesAt && savedEntry.meta.revalidatesAt < Date.now()) {
|
||||
|
||||
@@ -36,7 +36,7 @@ export async function trace<T>(
|
||||
},
|
||||
};
|
||||
|
||||
const _start = now();
|
||||
const start = now();
|
||||
try {
|
||||
return await fn(span);
|
||||
} catch (error) {
|
||||
@@ -44,7 +44,9 @@ export async function trace<T>(
|
||||
throw error;
|
||||
} finally {
|
||||
if (process.env.SILENT !== 'true') {
|
||||
const _end = now();
|
||||
const end = now();
|
||||
// biome-ignore lint/suspicious/noConsole: we want to log performance data
|
||||
console.log(`trace ${completeName} ${end - start}ms`, attributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user