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 delete domain

Kiran K744d1b204252
diff --git a/apps/web/lib/api/domains/delete-domain-links.ts b/apps/web/lib/api/domains/delete-domain-links.ts
index f72026eb18..aab588ef12 100644
--- a/apps/web/lib/api/domains/delete-domain-links.ts
+++ b/apps/web/lib/api/domains/delete-domain-links.ts
@@ -1,9 +1,9 @@
import { qstash } from "@/lib/cron";
import { prisma } from "@/lib/prisma";
-import { redis } from "@/lib/upstash";
import { APP_DOMAIN_WITH_NGROK, R2_URL } from "@dub/utils";
import { storage } from "../../storage";
import { recordLink } from "../../tinybird";
+import { linkCache } from "../links/cache";
import { removeDomainFromVercel } from "./remove-domain-vercel";
// Delete a domain and all links & images associated with it
@@ -28,12 +28,6 @@ export async function deleteDomainAndLinks({
return;
}
- const pipeline = redis.pipeline();
-
- links.forEach((link) => {
- pipeline.del(`${link.domain}:${link.key}`.toLowerCase());
- });
-
const response = await Promise.allSettled([
// Record link in the Tinybird
recordLink(
@@ -55,7 +49,7 @@ export async function deleteDomainAndLinks({
.map((link) => storage.delete(link.image!.replace(`${R2_URL}/`, ""))),
// Remove the link from Redis
- pipeline.exec(),
+ linkCache.deleteMany(links),
// Remove the link from MySQL
prisma.link.deleteMany({
diff --git a/apps/web/lib/api/links/bulk-delete-links.ts b/apps/web/lib/api/links/bulk-delete-links.ts
index 61240c5a02..8717d9b4d5 100644
--- a/apps/web/lib/api/links/bulk-delete-links.ts
+++ b/apps/web/lib/api/links/bulk-delete-links.ts
@@ -1,9 +1,9 @@
import { prisma } from "@/lib/prisma";
import { storage } from "@/lib/storage";
import { recordLink } from "@/lib/tinybird";
-import { redis } from "@/lib/upstash";
import { R2_URL } from "@dub/utils";
import { Link, Tag } from "@prisma/client";
+import { linkCache } from "./cache";
export async function bulkDeleteLinks({
links,
@@ -16,15 +16,9 @@ export async function bulkDeleteLinks({
return;
}
- const pipeline = redis.pipeline();
-
- links.forEach((link) => {
- pipeline.del(`${link.domain}:${link.key}`.toLowerCase());
- });
-
return await Promise.all([
// Delete the links from Redis
- pipeline.exec(),
+ linkCache.deleteMany(links),
// Record the links deletion in Tinybird
recordLink(
diff --git a/apps/web/lib/api/links/delete-link.ts b/apps/web/lib/api/links/delete-link.ts
index 44448b23a1..e9fac42d1a 100644
--- a/apps/web/lib/api/links/delete-link.ts
+++ b/apps/web/lib/api/links/delete-link.ts
@@ -1,9 +1,9 @@
import { prisma } from "@/lib/prisma";
import { storage } from "@/lib/storage";
import { recordLink } from "@/lib/tinybird";
-import { redis } from "@/lib/upstash";
import { R2_URL } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
+import { linkCache } from "./cache";
export async function deleteLink(linkId: string) {
const link = await prisma.link.delete({
@@ -35,7 +35,7 @@ export async function deleteLink(linkId: string) {
storage.delete(link.image.replace(`${R2_URL}/`, "")),
// Remove the link from Redis
- redis.hdel(`${link.domain}:${link.key}`.toLowerCase()),
+ linkCache.delete(link),
// Decrement the links count for the workspace
link.projectId &&