Skip to content

Commit

Permalink
perf: increase kv ttl; utilize waitUntil to send response without hav…
Browse files Browse the repository at this point in the history
…e to wait for stat to be added

Signed-off-by: Jubayer <[email protected]>
  • Loading branch information
ajshovon committed Nov 25, 2024
1 parent b59c5f9 commit 6c247ab
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions apps/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand Down

0 comments on commit 6c247ab

Please sign in to comment.