The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
wip redis
Kiran Kc1b86815df75
diff --git a/apps/web/lib/webhook/utils.ts b/apps/web/lib/webhook/utils.tsindex 30751afc64..e45b50d220 100644--- a/apps/web/lib/webhook/utils.ts+++ b/apps/web/lib/webhook/utils.ts@@ -1,3 +1,5 @@+import { prisma } from "@/lib/prisma";+import { formatRedisLink, redis } from "@/lib/upstash";import { Webhook } from "@prisma/client";interface TransformWebhookProps@@ -5,6 +7,7 @@ interface TransformWebhookPropslinkWebhooks: { linkId: string }[];}+// Transform webhookexport const transformWebhook = (webhook: TransformWebhookProps) => {return {id: webhook.id,@@ -15,3 +18,44 @@ export const transformWebhook = (webhook: TransformWebhookProps) => {linkIds: webhook.linkWebhooks.map((linkWebhook) => linkWebhook.linkId),};};++// Update webhooks in redis for a link+export const updateLinksInRedis = async ({+ linkIds,+ webhook,+}: {+ linkIds: string[];+ webhook: Pick<Webhook, "id" | "url" | "secret" | "triggers">;+}) => {+ const links = await prisma.link.findMany({+ where: {+ id: { in: linkIds },+ },+ });++ const pipeline = redis.pipeline();++ const formatedLinks = await Promise.all(+ links.map(async (link) => {+ return {+ ...(await formatRedisLink(link)),+ webhook: {+ id: webhook.id,+ url: webhook.url,+ secret: webhook.secret,+ triggers: webhook.triggers,+ },+ };+ }),+ );++ // formatedLinks.map((formatedLink) => {+ // const { webhook, ...rest } = formatedLink;++ // pipeline.hset(link.key.toLowerCase(), {+ // [formatedLink.key]: rest,+ // });+ // });++ // await pipeline.exec();+};