From 8cd392a3c1993796ac8cb6f6b67f11709b9e0a20 Mon Sep 17 00:00:00 2001 From: gimenes Date: Wed, 17 May 2023 16:22:21 -0300 Subject: [PATCH 1/5] wip --- utils/fetch.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/utils/fetch.ts b/utils/fetch.ts index 9c20745c..545b41cf 100644 --- a/utils/fetch.ts +++ b/utils/fetch.ts @@ -68,6 +68,16 @@ export const fetchSafe = async ( await fetch(url, init) ); + const isGet = !init?.method || init.method === "GET"; + const isHit = response.headers.get("x-cache") === "HIT"; + const servedBy = response.headers.get("x-served-by"); + if (isGet) { + if (!isHit) { + console.log(`${url}`, response.headers); + } + console.log({ servedBy }); + } + if (response.ok) { return response; } From d913a80d06b15388361c0e96ba90b28faf17986b Mon Sep 17 00:00:00 2001 From: gimenes Date: Wed, 17 May 2023 16:42:07 -0300 Subject: [PATCH 2/5] wip2 --- schemas.gen.json | 2 +- utils/fetch.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/schemas.gen.json b/schemas.gen.json index b9a5d5ae..f69d739c 100644 --- a/schemas.gen.json +++ b/schemas.gen.json @@ -10328,4 +10328,4 @@ } } } -} \ No newline at end of file +} diff --git a/utils/fetch.ts b/utils/fetch.ts index 545b41cf..16f107c2 100644 --- a/utils/fetch.ts +++ b/utils/fetch.ts @@ -64,18 +64,18 @@ export const fetchSafe = async ( ) => { const url = init?.withProxyCache ? await toProxyCache(input, init) : input; + const start = performance.now(); const response = await retryExceptionOr500.execute(async () => await fetch(url, init) ); + const duration = performance.now() - start; const isGet = !init?.method || init.method === "GET"; const isHit = response.headers.get("x-cache") === "HIT"; const servedBy = response.headers.get("x-served-by"); + if (isGet) { - if (!isHit) { - console.log(`${url}`, response.headers); - } - console.log({ servedBy }); + console.log(`[${duration}ms]: hit: ${isHit}, servedBy: ${servedBy}`); } if (response.ok) { From b2664018d3b61c455c5df6c0f0471f1070e51283 Mon Sep 17 00:00:00 2001 From: gimenes Date: Wed, 17 May 2023 16:43:51 -0300 Subject: [PATCH 3/5] wip --- utils/fetch.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/fetch.ts b/utils/fetch.ts index 16f107c2..25be2ace 100644 --- a/utils/fetch.ts +++ b/utils/fetch.ts @@ -75,7 +75,9 @@ export const fetchSafe = async ( const servedBy = response.headers.get("x-served-by"); if (isGet) { - console.log(`[${duration}ms]: hit: ${isHit}, servedBy: ${servedBy}`); + console.log( + `[${duration.toFixed(0)}ms]: hit: ${isHit}, servedBy: ${servedBy}`, + ); } if (response.ok) { From 5913a03a18e0803865a20216f7c75b7f48470b63 Mon Sep 17 00:00:00 2001 From: gimenes Date: Wed, 17 May 2023 17:06:45 -0300 Subject: [PATCH 4/5] wip fetch --- utils/fetch.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/utils/fetch.ts b/utils/fetch.ts index 25be2ace..15ef3a92 100644 --- a/utils/fetch.ts +++ b/utils/fetch.ts @@ -65,11 +65,9 @@ export const fetchSafe = async ( const url = init?.withProxyCache ? await toProxyCache(input, init) : input; const start = performance.now(); - const response = await retryExceptionOr500.execute(async () => - await fetch(url, init) - ); - + const response = await fetch(url, init); const duration = performance.now() - start; + const isGet = !init?.method || init.method === "GET"; const isHit = response.headers.get("x-cache") === "HIT"; const servedBy = response.headers.get("x-served-by"); From 542f39160e0f7e346830f2b0b017329938244466 Mon Sep 17 00:00:00 2001 From: gimenes Date: Wed, 17 May 2023 17:17:13 -0300 Subject: [PATCH 5/5] age --- utils/fetch.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/fetch.ts b/utils/fetch.ts index 15ef3a92..33963801 100644 --- a/utils/fetch.ts +++ b/utils/fetch.ts @@ -71,10 +71,13 @@ export const fetchSafe = async ( const isGet = !init?.method || init.method === "GET"; const isHit = response.headers.get("x-cache") === "HIT"; const servedBy = response.headers.get("x-served-by"); + const age = response.headers.get("Age"); if (isGet) { console.log( - `[${duration.toFixed(0)}ms]: hit: ${isHit}, servedBy: ${servedBy}`, + `[${ + duration.toFixed(0) + }ms]: hit: ${isHit}, servedBy: ${servedBy}, age: ${age}`, ); }