The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update route.ts
Kiran K506eb18b64e9
diff --git a/apps/web/app/api/cron/links/sync-tinybird/route.ts b/apps/web/app/api/cron/links/sync-tinybird/route.tsindex 2372db0b44..62a8a75e4e 100644--- a/apps/web/app/api/cron/links/sync-tinybird/route.ts+++ b/apps/web/app/api/cron/links/sync-tinybird/route.ts@@ -1,5 +1,7 @@import { handleAndReturnErrorResponse } from "@/lib/api/errors";+import { scheduleLinkSync } from "@/lib/api/links/utils/sync-links";import { verifyQstashSignature } from "@/lib/cron/verify-qstash";+import { recordLink } from "@/lib/tinybird";import { prisma } from "@dub/prisma";import { z } from "zod";@@ -41,15 +43,39 @@ export async function POST(req: Request) {return new Response("No links found in the folder. Skipping...");}- // TODO:- // Find 100 of 5 batches of links- // - call recordLink for each link- // - Update the folderId to null for each link- // invoke scheduleLinkSync with another batch+ const links = await prisma.link.findMany({+ where: {+ folderId,+ },+ include: {+ tags: {+ select: {+ tag: true,+ },+ },+ },+ take: 500,+ });+ await recordLink(links);+ await prisma.link.updateMany({+ where: {+ id: {+ in: links.map((link) => link.id),+ },+ },+ data: {+ folderId: null,+ },+ });++ await scheduleLinkSync({+ folderId,+ delay: 2,+ });- return new Response("Link synced to Tinybird.");+ return new Response(`Processed ${links.length} links in the folder.`);} catch (error) {return handleAndReturnErrorResponse(error);}