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.

Enhance webhook management by adding propagateWebhookTriggerChanges to create and update link functions, and implement deleteMany method in WebhookCache for batch deletion of webhook caches.

Kiran Kfaa884d91bad
diff --git a/apps/web/lib/api/links/create-link.ts b/apps/web/lib/api/links/create-link.ts
index d5afba7b1f..767803bcce 100644
--- a/apps/web/lib/api/links/create-link.ts
+++ b/apps/web/lib/api/links/create-link.ts
@@ -2,6 +2,7 @@ import { qstash } from "@/lib/cron";
import { isStored, storage } from "@/lib/storage";
import { recordLink } from "@/lib/tinybird";
import { ProcessedLinkProps } from "@/lib/types";
+import { propagateWebhookTriggerChanges } from "@/lib/webhook/update-webhook";
import { prisma } from "@dub/prisma";
import { Prisma } from "@dub/prisma/client";
import {
@@ -174,6 +175,11 @@ export async function createLink(link: ProcessedLinkProps) {
workspaceId: link.projectId,
increment: 1,
}),
+
+ webhookIds &&
+ propagateWebhookTriggerChanges({
+ webhookIds,
+ }),
]),
);
diff --git a/apps/web/lib/api/links/update-link.ts b/apps/web/lib/api/links/update-link.ts
index 4ea3a2cc3f..f79f501ca4 100644
--- a/apps/web/lib/api/links/update-link.ts
+++ b/apps/web/lib/api/links/update-link.ts
@@ -1,6 +1,7 @@
import { isStored, storage } from "@/lib/storage";
import { recordLink } from "@/lib/tinybird";
import { LinkProps, ProcessedLinkProps } from "@/lib/types";
+import { propagateWebhookTriggerChanges } from "@/lib/webhook/update-webhook";
import { prisma } from "@dub/prisma";
import { Prisma } from "@dub/prisma/client";
import {
@@ -182,6 +183,11 @@ export async function updateLink({
oldLink.image.startsWith(`${R2_URL}/images/${id}`) &&
oldLink.image !== image &&
storage.delete(oldLink.image.replace(`${R2_URL}/`, "")),
+
+ webhookIds != undefined &&
+ propagateWebhookTriggerChanges({
+ webhookIds,
+ }),
]),
);
diff --git a/apps/web/lib/webhook/cache.ts b/apps/web/lib/webhook/cache.ts
index 8446c2b35b..c2eee72c10 100644
--- a/apps/web/lib/webhook/cache.ts
+++ b/apps/web/lib/webhook/cache.ts
@@ -40,6 +40,20 @@ class WebhookCache {
return await redis.del(this._createKey(webhookId));
}
+ async deleteMany(webhookIds: string[]) {
+ if (webhookIds.length === 0) {
+ return;
+ }
+
+ const pipeline = redis.pipeline();
+
+ webhookIds.map((webhookId) => {
+ pipeline.del(this._createKey(webhookId));
+ });
+
+ return await pipeline.exec();
+ }
+
_format(webhook: WebhookCacheProps) {
return {
id: webhook.id,