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.

fix updating cache

Kiran K497477fdf936
diff --git a/apps/web/app/api/webhooks/[webhookId]/route.ts b/apps/web/app/api/webhooks/[webhookId]/route.ts
index b949546ec2..6a62b4b3b1 100644
--- a/apps/web/app/api/webhooks/[webhookId]/route.ts
+++ b/apps/web/app/api/webhooks/[webhookId]/route.ts
@@ -192,13 +192,9 @@ export const PATCH = withWorkspace(
(linkId) => !newLinkIds.includes(linkId),
);
- const linksToBeUpdated = [...linksAdded, ...linksRemoved];
-
- console.log("linksToBeUpdated", linksToBeUpdated);
-
const links = await prisma.link.findMany({
where: {
- id: { in: linksToBeUpdated },
+ id: { in: [...linksAdded, ...linksRemoved] },
},
include: {
webhooks: {
@@ -212,7 +208,9 @@ export const PATCH = withWorkspace(
const formatedLinks = links.map((link) => {
return {
...link,
- webhookIds: link.webhooks.map(({ webhookId }) => webhookId),
+ ...(link.webhooks.length > 0 && {
+ webhookIds: link.webhooks.map(({ webhookId }) => webhookId),
+ }),
};
});
@@ -240,6 +238,15 @@ export const DELETE = withWorkspace(
async ({ workspace, params }) => {
const { webhookId } = params;
+ const linkWebhooks = await prisma.linkWebhook.findMany({
+ where: {
+ webhookId,
+ },
+ select: {
+ linkId: true,
+ },
+ });
+
await prisma.webhook.delete({
where: {
id: webhookId,
@@ -267,20 +274,9 @@ export const DELETE = withWorkspace(
waitUntil(
(async () => {
- const linkWebhooks = await prisma.linkWebhook.findMany({
- where: {
- webhookId,
- },
- select: {
- linkId: true,
- },
- });
-
- const linkIds = linkWebhooks.map(({ linkId }) => linkId);
-
const links = await prisma.link.findMany({
where: {
- id: { in: linkIds },
+ id: { in: linkWebhooks.map(({ linkId }) => linkId) },
},
include: {
webhooks: {
diff --git a/apps/web/lib/api/links/update-link.ts b/apps/web/lib/api/links/update-link.ts
index bb54523aa0..53879e69e5 100644
--- a/apps/web/lib/api/links/update-link.ts
+++ b/apps/web/lib/api/links/update-link.ts
@@ -125,7 +125,9 @@ export async function updateLink({
redis.hset(updatedLink.domain.toLowerCase(), {
[updatedLink.key.toLowerCase()]: await formatRedisLink({
...response,
- webhookIds: response.webhooks.map(({ webhookId }) => webhookId),
+ ...(response.webhooks.length > 0 && {
+ webhookIds: response.webhooks.map(({ webhookId }) => webhookId),
+ }),
}),
}),
// record link in Tinybird