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.

delete link

Kiran K9fa60a194739
diff --git a/apps/web/lib/api/domains/delete-domain-links.ts b/apps/web/lib/api/domains/delete-domain-links.ts
index 7d0c68a4c2..f59c172a29 100644
--- a/apps/web/lib/api/domains/delete-domain-links.ts
+++ b/apps/web/lib/api/domains/delete-domain-links.ts
@@ -63,6 +63,18 @@ export async function deleteDomainAndLinks({
id: { in: links.map((link) => link.id) },
},
}),
+
+ // Decrement the links count for the workspace
+ prisma.project.update({
+ where: {
+ id: workspaceId,
+ },
+ data: {
+ linksUsage: {
+ decrement: links.length,
+ },
+ },
+ }),
]);
response.forEach((promise) => {
diff --git a/apps/web/lib/api/links/delete-link.ts b/apps/web/lib/api/links/delete-link.ts
index 3b8390bd8a..44448b23a1 100644
--- a/apps/web/lib/api/links/delete-link.ts
+++ b/apps/web/lib/api/links/delete-link.ts
@@ -14,13 +14,10 @@ export async function deleteLink(linkId: string) {
tags: true,
},
});
+
waitUntil(
Promise.allSettled([
- // if there's a valid image and it has the same link ID, delete it
- link.image &&
- link.image.startsWith(`${R2_URL}/images/${link.id}`) &&
- storage.delete(link.image.replace(`${R2_URL}/`, "")),
- redis.hdel(link.domain.toLowerCase(), link.key.toLowerCase()),
+ // Record link in the Tinybird
recordLink({
link_id: link.id,
domain: link.domain,
@@ -31,6 +28,16 @@ export async function deleteLink(linkId: string) {
created_at: link.createdAt,
deleted: true,
}),
+
+ // Remove image from R2 storage if it exists
+ link.image &&
+ link.image.startsWith(`${R2_URL}/images/${link.id}`) &&
+ storage.delete(link.image.replace(`${R2_URL}/`, "")),
+
+ // Remove the link from Redis
+ redis.hdel(`${link.domain}:${link.key}`.toLowerCase()),
+
+ // Decrement the links count for the workspace
link.projectId &&
prisma.project.update({
where: {