The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
linkCache.expireMany instead of linkCache.rename
Steven Tey818ad808f17c
diff --git a/apps/web/app/api/cron/domains/update/route.ts b/apps/web/app/api/cron/domains/update/route.tsindex 33b0540128..b8c82dc877 100644--- a/apps/web/app/api/cron/domains/update/route.ts+++ b/apps/web/app/api/cron/domains/update/route.ts@@ -33,23 +33,23 @@ export async function POST(req: Request) {return new Response(`Domain ${newDomain} not found. Skipping update...`);}- const links = await prisma.link.findMany({+ const linksToUpdate = await prisma.link.findMany({where: {domain: oldDomain,},take: 100,});- if (links.length === 0) {+ if (linksToUpdate.length === 0) {return new Response("No more links to update. Exiting...");}- const linkIds = links.map((link) => link.id);+ const linkIdsToUpdate = linksToUpdate.map((link) => link.id);await prisma.link.updateMany({where: {id: {- in: linkIds,+ in: linkIdsToUpdate,},},data: {@@ -60,7 +60,7 @@ export async function POST(req: Request) {const updatedLinks = await prisma.link.findMany({where: {id: {- in: linkIds,+ in: linkIdsToUpdate,},},include: {@@ -73,14 +73,12 @@ export async function POST(req: Request) {});await Promise.all([- linkCache.rename({- links: updatedLinks,- oldDomain,- }),-- recordLink(updatedLinks),-+ // update the `shortLink` field for each of the short linksupdateShortLinks(updatedLinks),+ // record new link values in Tinybird (dub_links_metadata)+ recordLink(updatedLinks),+ // expire the redis cache for the old links+ linkCache.expireMany(linksToUpdate),]);await queueDomainUpdate({diff --git a/apps/web/lib/api/links/cache.ts b/apps/web/lib/api/links/cache.tsindex 958c937302..fc0363637e 100644--- a/apps/web/lib/api/links/cache.ts+++ b/apps/web/lib/api/links/cache.ts@@ -75,33 +75,6 @@ class LinkCache {return await pipeline.exec();}- async rename({- links,- oldDomain,- }: {- links: Pick<LinkProps, "domain" | "key">[];- oldDomain: string;- }) {- if (links.length === 0) {- return;- }-- const pipeline = redis.pipeline();-- links.forEach(({ domain, key }) => {- const oldCacheKey = this._createKey({ domain: oldDomain, key });- const newCacheKey = this._createKey({ domain, key });-- pipeline.rename(oldCacheKey, newCacheKey);- });-- try {- return await pipeline.exec();- } catch (_error) {- return null;- }- }-async expireMany(links: Pick<LinkProps, "domain" | "key">[]) {if (links.length === 0) {return;