From 6c247abc6c7e759e523d9e7c7bec8a97b291aab1 Mon Sep 17 00:00:00 2001 From: Jubayer Date: Mon, 25 Nov 2024 12:07:51 +0600 Subject: [PATCH] perf: increase kv ttl; utilize waitUntil to send response without have to wait for stat to be added Signed-off-by: Jubayer --- apps/api/src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index 1a4b42d..78efcd4 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -37,7 +37,7 @@ app.get('/:id', async (c) => { const kvData = await kv.get(id); if (kvData) { console.log('Served from KV'); - await addStat(c, id); + c.executionCtx.waitUntil(addStat(c, link.slug)); return c.redirect(kvData); } @@ -51,9 +51,9 @@ app.get('/:id', async (c) => { throw new HTTPException(404); } else { console.log('Served from database'); - await kv.put(id, link.dest); + await kv.put(id, link.dest, { expirationTtl: 60 * 60 * 24 * 30 }); - await addStat(c, link.slug); + c.executionCtx.waitUntil(addStat(c, link.slug)); return c.redirect(link.dest); }