Skip to content

Commit e55f69f

Browse files
committed
chore: add some timestamps to debug logs
1 parent db18c63 commit e55f69f

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/run/handlers/use-cache-handler.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ function getPendingSets(): PendingSets {
8686
return pendingSets
8787
}
8888

89+
const debugLog = (...args: unknown[]) => console.log(new Date().toISOString(), ...args)
90+
8991
// eslint-disable-next-line @typescript-eslint/no-empty-function
9092
const tmpResolvePendingBeforeCreatingAPromise = () => {}
9193

@@ -207,6 +209,10 @@ const WIPNetlifyDefaultUseCacheHandler = {
207209
},
208210
async refreshTags(): Promise<void> {
209211
// we check tags on demand, so we don't need to do anything here
212+
// additionally this is blocking and we do need to check tags in
213+
// persisted storage, so if we would maintain in-memory tags manifests
214+
// we would need to check more tags than current request needs
215+
// while blocking pipeline
210216
},
211217
getExpiration: function (...tags: string[]): ReturnType<CacheHandler['getExpiration']> {
212218
return getTracer().withActiveSpan(
@@ -243,10 +249,10 @@ const WIPNetlifyDefaultUseCacheHandler = {
243249
function createDebugUseCacheHandler(cacheHandlerToDebug: CacheHandler): CacheHandler {
244250
return {
245251
get: function (cacheKey: string): Promise<undefined | CacheEntry> {
246-
console.log('NetlifyDefaultUseCacheHandler::get start', { cacheKey })
252+
debugLog('NetlifyDefaultUseCacheHandler::get start', { cacheKey })
247253
return cacheHandlerToDebug.get(cacheKey).then(async (entry) => {
248254
if (!entry) {
249-
console.log('NetlifyDefaultUseCacheHandler::get MISS', { cacheKey })
255+
debugLog('NetlifyDefaultUseCacheHandler::get MISS', { cacheKey })
250256
return entry
251257
}
252258

@@ -256,7 +262,7 @@ function createDebugUseCacheHandler(cacheHandlerToDebug: CacheHandler): CacheHan
256262
const [returnStream, debugStream] = cloneStream.tee()
257263

258264
const text = await new Response(debugStream).text()
259-
console.log('NetlifyDefaultUseCacheHandler::get HIT', { cacheKey, entry, text })
265+
debugLog('NetlifyDefaultUseCacheHandler::get HIT', { cacheKey, entry, text })
260266

261267
return {
262268
...entry,
@@ -265,7 +271,7 @@ function createDebugUseCacheHandler(cacheHandlerToDebug: CacheHandler): CacheHan
265271
})
266272
},
267273
set: async function (cacheKey: string, pendingEntry: Promise<CacheEntry>): Promise<void> {
268-
console.log('NetlifyDefaultUseCacheHandler::set start', { cacheKey })
274+
debugLog('NetlifyDefaultUseCacheHandler::set start', { cacheKey })
269275
const entry = await pendingEntry
270276
const [storeStream, debugStream] = entry.value.tee()
271277

@@ -276,33 +282,35 @@ function createDebugUseCacheHandler(cacheHandlerToDebug: CacheHandler): CacheHan
276282

277283
const text = await new Response(debugStream).text()
278284

279-
console.log('NetlifyDefaultUseCacheHandler::set awaited pending entry', {
285+
debugLog('NetlifyDefaultUseCacheHandler::set awaited pending entry', {
280286
cacheKey,
281287
entry,
282288
text,
283289
})
284290

285291
const setPromise = cacheHandlerToDebug.set(cacheKey, toSetEntry).then(() => {
286-
console.log('NetlifyDefaultUseCacheHandler::set finish', { cacheKey })
292+
debugLog('NetlifyDefaultUseCacheHandler::set finish', { cacheKey })
287293
})
288294

289295
getRequestContext()?.trackBackgroundWork(setPromise)
290296

291297
return setPromise
292298
},
293299
refreshTags: function (): Promise<void> {
294-
console.log('NetlifyDefaultUseCacheHandler::refreshTags')
295-
return cacheHandlerToDebug.refreshTags()
300+
debugLog('NetlifyDefaultUseCacheHandler::refreshTags start')
301+
return cacheHandlerToDebug.refreshTags().then(() => {
302+
debugLog('NetlifyDefaultUseCacheHandler::refreshTags end')
303+
})
296304
},
297305
getExpiration: function (...tags: string[]): Promise<Timestamp> {
298-
console.log('NetlifyDefaultUseCacheHandler::getExpiration start', { tags })
306+
debugLog('NetlifyDefaultUseCacheHandler::getExpiration start', { tags })
299307
return cacheHandlerToDebug.getExpiration(...tags).then((expiration) => {
300-
console.log('NetlifyDefaultUseCacheHandler::getExpiration finish', { tags, expiration })
308+
debugLog('NetlifyDefaultUseCacheHandler::getExpiration finish', { tags, expiration })
301309
return expiration
302310
})
303311
},
304312
expireTags: function (...tags: string[]): Promise<void> {
305-
console.log('NetlifyDefaultUseCacheHandler::expireTags', { tags })
313+
debugLog('NetlifyDefaultUseCacheHandler::expireTags', { tags })
306314
return cacheHandlerToDebug.expireTags(...tags)
307315
},
308316
}

0 commit comments

Comments
 (0)