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.

revert deleteLink changes

Kiran Ke77c2e6b6225
diff --git a/apps/web/lib/api/links/delete-link.ts b/apps/web/lib/api/links/delete-link.ts
index c34529834e..3b8390bd8a 100644
--- a/apps/web/lib/api/links/delete-link.ts
+++ b/apps/web/lib/api/links/delete-link.ts
@@ -3,14 +3,8 @@ import { storage } from "@/lib/storage";
import { recordLink } from "@/lib/tinybird";
import { redis } from "@/lib/upstash";
import { R2_URL } from "@dub/utils";
-import { Link } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
-type LinkWithTags = Pick<
- Link,
- "id" | "image" | "domain" | "key" | "projectId" | "createdAt" | "url"
-> & { tags: { tagId: string }[] };
-
export async function deleteLink(linkId: string) {
const link = await prisma.link.delete({
where: {
@@ -20,44 +14,36 @@ 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()),
+ recordLink({
+ link_id: link.id,
+ domain: link.domain,
+ key: link.key,
+ url: link.url,
+ tag_ids: link.tags.map((tag) => tag.tagId),
+ workspace_id: link.projectId,
+ created_at: link.createdAt,
+ deleted: true,
+ }),
+ link.projectId &&
+ prisma.project.update({
+ where: {
+ id: link.projectId,
+ },
+ data: {
+ linksUsage: {
+ decrement: 1,
+ },
+ },
+ }),
+ ]),
+ );
- waitUntil(finalizeLinkDeletion(link));
+ return link;
}
-
-// Post-delete cleanup
-export const finalizeLinkDeletion = async (link: LinkWithTags) => {
- return 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}/`, "")),
-
- // Delete the link from Redis
- redis.hdel(link.domain.toLowerCase(), link.key.toLowerCase()),
-
- // Record the link deletion in Tinybird
- recordLink({
- link_id: link.id,
- domain: link.domain,
- key: link.key,
- url: link.url,
- tag_ids: link.tags.map((tag) => tag.tagId),
- workspace_id: link.projectId,
- created_at: link.createdAt,
- deleted: true,
- }),
-
- // Decrement the project's links usage
- link.projectId &&
- prisma.project.update({
- where: {
- id: link.projectId,
- },
- data: {
- linksUsage: {
- decrement: 1,
- },
- },
- }),
- ]);
-};