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.

add scripts

Steven Teyeff02dd557e1
diff --git a/apps/web/scripts/backfill-link-webhooks.ts b/apps/web/scripts/backfill-link-webhooks.ts
new file mode 100644
index 0000000000..9cd08d3a8b
--- /dev/null
+++ b/apps/web/scripts/backfill-link-webhooks.ts
@@ -0,0 +1,25 @@
+import { prisma } from "@dub/prisma";
+import "dotenv-flow/config";
+import { linkCache } from "../lib/api/links/cache";
+
+// script to backfill link cache for links with webhooks
+async function main() {
+ const links = await prisma.link.findMany({
+ where: {
+ webhooks: {
+ some: {},
+ },
+ },
+ include: {
+ webhooks: true,
+ },
+ });
+
+ console.log(links.length);
+ console.log(JSON.stringify(links, null, 2));
+
+ const res = await linkCache.mset(links);
+ console.log(res);
+}
+
+main();
diff --git a/apps/web/scripts/purge-old-link-cache.ts b/apps/web/scripts/purge-old-link-cache.ts
new file mode 100644
index 0000000000..d75e3564dd
--- /dev/null
+++ b/apps/web/scripts/purge-old-link-cache.ts
@@ -0,0 +1,23 @@
+import { prisma } from "@dub/prisma";
+import "dotenv-flow/config";
+import { redis } from "../lib/upstash";
+
+const batch = 3;
+
+// script to remove old redis link cache entries
+async function main() {
+ const domains = await prisma.domain.findMany({
+ orderBy: {
+ createdAt: "asc",
+ },
+ take: 500,
+ skip: batch * 500,
+ });
+
+ for (const domain of domains) {
+ const res = await redis.del(domain.slug);
+ console.log(`Deleted ${domain.slug} from redis: ${res}`);
+ }
+}
+
+main();