The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Ratelimit token update function (every 15 min)
Steven Tey1f89bfe55f41
diff --git a/apps/web/lib/auth/workspace.ts b/apps/web/lib/auth/workspace.tsindex 66ad62c2c4..e187c746e2 100644--- a/apps/web/lib/auth/workspace.ts+++ b/apps/web/lib/auth/workspace.ts@@ -232,21 +232,27 @@ export const withWorkspace = (}waitUntil(- // update last used time for the token+ // update last used time for the token (only once every 15 minutes)(async () => {- const prismaArgs = {- where: {- hashedKey,- },- data: {- lastUsed: new Date(),- },- };+ const { success } = await ratelimit(1, "15 m").limit(+ `last-used-${hashedKey}`,+ );++ if (success) {+ const prismaArgs = {+ where: {+ hashedKey,+ },+ data: {+ lastUsed: new Date(),+ },+ };- if (isRestrictedToken) {- await prisma.restrictedToken.update(prismaArgs);- } else {- await prisma.token.update(prismaArgs);+ if (isRestrictedToken) {+ await prisma.restrictedToken.update(prismaArgs);+ } else {+ await prisma.token.update(prismaArgs);+ }}})(),);