Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

skip cache update if no links changed

Kiran Kbe774938166b
diff --git a/apps/web/app/api/webhooks/[webhookId]/route.ts b/apps/web/app/api/webhooks/[webhookId]/route.ts
index 6a62b4b3b1..782dd6802b 100644
--- a/apps/web/app/api/webhooks/[webhookId]/route.ts
+++ b/apps/web/app/api/webhooks/[webhookId]/route.ts
@@ -179,7 +179,6 @@ export const PATCH = withWorkspace(
const newLinkIds = webhook.links.map(({ linkId }) => linkId);
const oldLinkIds = oldLinks.map(({ linkId }) => linkId);
- // No changes in the links
if (!newLinkIds.length && !oldLinkIds.length) {
return;
}
@@ -192,6 +191,11 @@ export const PATCH = withWorkspace(
(linkId) => !newLinkIds.includes(linkId),
);
+ // No changes in the links
+ if (!linksAdded.length && !linksRemoved.length) {
+ return;
+ }
+
const links = await prisma.link.findMany({
where: {
id: { in: [...linksAdded, ...linksRemoved] },
diff --git a/apps/web/lib/api/links/cache.ts b/apps/web/lib/api/links/cache.ts
index 3f1e59839e..b8594c56f8 100644
--- a/apps/web/lib/api/links/cache.ts
+++ b/apps/web/lib/api/links/cache.ts
@@ -3,6 +3,10 @@ import { formatRedisLink, redis } from "@/lib/upstash";
class LinkCache {
async mset(links: (LinkProps & { webhookIds?: string[] })[]) {
+ if (links.length === 0) {
+ return;
+ }
+
const pipeline = redis.pipeline();
const redisLinks = await Promise.all(