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.

speed up cron importer

Steven Tey4890e4a7a83d
diff --git a/apps/web/app/api/cron/import/bitly/utils.ts b/apps/web/app/api/cron/import/bitly/utils.ts
index 736d7db884..b2737f5451 100644
--- a/apps/web/app/api/cron/import/bitly/utils.ts
+++ b/apps/web/app/api/cron/import/bitly/utils.ts
@@ -1,5 +1,4 @@
import { bulkCreateLinks } from "@/lib/api/links";
-import { linkCache } from "@/lib/api/links/cache";
import {
decodeLinkIfCaseSensitive,
encodeKeyIfCaseSensitive,
@@ -202,40 +201,6 @@ export const importLinksFromBitly = async ({
// bulk create links
await bulkCreateLinks({ links: linksToCreate, skipRedisCache: true });
- // only for buff.ly: check if previously created links (without case sensitivity) exists, if so, delete them + expire their cache
- if (domains.includes("buff.ly")) {
- const previouslyCreatedLinks = await prisma.link.findMany({
- where: {
- shortLink: {
- in: importedLinks.map((link) => link.shortLink),
- },
- },
- select: {
- id: true,
- domain: true,
- key: true,
- },
- });
-
- console.log(
- `Found ${previouslyCreatedLinks.length} buff.ly links that were imported without case sensitivity, deleting them...`,
- );
-
- // delete links that exist as unhashed versions (only for buff.ly domain)
- if (previouslyCreatedLinks.length) {
- await Promise.allSettled([
- prisma.link.deleteMany({
- where: {
- id: {
- in: previouslyCreatedLinks.map((link) => link.id),
- },
- },
- }),
- linkCache.expireMany(previouslyCreatedLinks),
- ]);
- }
- }
-
count += importedLinks.length;
console.log({
@@ -245,8 +210,8 @@ export const importLinksFromBitly = async ({
nextSearchAfter,
});
- // wait 500 ms before making another request
- await new Promise((resolve) => setTimeout(resolve, 500));
+ // wait 250 ms before making another request
+ await new Promise((resolve) => setTimeout(resolve, 250));
if (nextSearchAfter === "") {
const workspace = await prisma.project.findUnique({
diff --git a/apps/web/scripts/buffer/migrate-to-case-sensitive.ts b/apps/web/scripts/buffer/migrate-to-case-sensitive.ts
index c17d5e8035..214a8af363 100644
--- a/apps/web/scripts/buffer/migrate-to-case-sensitive.ts
+++ b/apps/web/scripts/buffer/migrate-to-case-sensitive.ts
@@ -16,7 +16,7 @@ async function main() {
domain,
folderId: oldFolderId,
createdAt: {
- lte: new Date("2025-03-07"), // TODO: update this to the timestamp when the PR is merged
+ lte: new Date("2025-03-07T16:33:32.084Z"),
},
},
select: {
@@ -24,7 +24,10 @@ async function main() {
domain: true,
key: true,
},
- take: 500,
+ take: 100,
+ orderBy: {
+ createdAt: "desc",
+ },
});
if (!links.length) {
@@ -32,30 +35,34 @@ async function main() {
return;
}
- for (const link of links) {
- const newKey = encodeKeyIfCaseSensitive({
- domain,
- key: link.key,
- });
-
- const newShortLink = linkConstructorSimple({
- domain,
- key: newKey,
- });
+ await Promise.allSettled(
+ links.map(async (link) => {
+ const newKey = encodeKeyIfCaseSensitive({
+ domain,
+ key: link.key,
+ });
- await prisma.link.update({
- where: {
- id: link.id,
- },
- data: {
+ const newShortLink = linkConstructorSimple({
+ domain,
key: newKey,
- shortLink: newShortLink,
- folderId: newFolderId,
- },
- });
+ });
- console.log(`Updated link ${link.id} to ${newShortLink}`);
- }
+ await prisma.link.update({
+ where: {
+ id: link.id,
+ },
+ data: {
+ key: newKey,
+ shortLink: newShortLink,
+ folderId: newFolderId,
+ },
+ });
+
+ console.log(
+ `Updated link ${link.id} to ${newShortLink} and new folder ${newFolderId}`,
+ );
+ }),
+ );
// expire the Redis cache for the links so it fetches the latest version from the database
await linkCache.expireMany(links);
diff --git a/apps/web/scripts/tella/export-partners.ts b/apps/web/scripts/tella/export-partners.ts
new file mode 100644
index 0000000000..5ea59e7334
--- /dev/null
+++ b/apps/web/scripts/tella/export-partners.ts
@@ -0,0 +1,28 @@
+import { prisma } from "@dub/prisma";
+import "dotenv-flow/config";
+import * as fs from "fs";
+import * as Papa from "papaparse";
+
+// update commissions for a program
+async function main() {
+ const partners = await prisma.programEnrollment
+ .findMany({
+ where: {
+ programId: "prog_xxx",
+ status: "approved",
+ },
+ select: {
+ partner: {
+ select: {
+ name: true,
+ email: true,
+ },
+ },
+ },
+ })
+ .then((partners) => partners.map(({ partner }) => partner));
+
+ fs.writeFileSync("tella_partners.csv", Papa.unparse(partners));
+}
+
+main();