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.

updated scripts

Steven Teyaef474b87fbe
diff --git a/apps/web/scripts/sync-domain-clicks.ts b/apps/web/scripts/sync-domain-clicks.ts
index 03474c7cbc..6b97778a5f 100644
--- a/apps/web/scripts/sync-domain-clicks.ts
+++ b/apps/web/scripts/sync-domain-clicks.ts
@@ -3,6 +3,7 @@ import * as Papa from "papaparse";
import * as fs from "fs";
import prisma from "@/lib/prisma";
+const index = 1000;
const domainClicks: { domain: string; clicks: string }[] = [];
async function main() {
@@ -12,11 +13,29 @@ async function main() {
domainClicks.push(result.data);
},
complete: async () => {
+ const domainWithClicks = await prisma.domain.findMany({
+ where: {
+ clicks: {
+ gt: 0,
+ },
+ },
+ select: {
+ slug: true,
+ },
+ });
console.table(domainClicks.slice(0, 50));
- domainClicks.forEach(async (domainClick) => {
- const { domain, clicks } = domainClick;
- try {
- await prisma.domain.update({
+ const domainClickToUpdate = domainClicks
+ .filter((domainClick) => {
+ const { domain } = domainClick;
+ return domainWithClicks.find(({ slug }) => slug === domain);
+ })
+ .slice(index, index + 1000);
+
+ await Promise.all(
+ domainClickToUpdate.map(async (domainClick) => {
+ const { domain, clicks } = domainClick;
+ console.log(`Updating ${domain} with ${clicks} clicks.`);
+ return prisma.domain.update({
where: {
slug: domain,
},
@@ -24,11 +43,13 @@ async function main() {
clicks: parseInt(clicks),
},
});
- console.log(`Updated ${domain} with ${clicks} clicks.`);
- } catch (e) {
- console.log(`${domain} doesn't exist, skipping.`);
- }
- });
+ }),
+ );
+ console.log(
+ `Done updating ${index} to ${
+ index + domainClickToUpdate.length
+ } domains.`,
+ );
},
});
}
diff --git a/apps/web/scripts/sync-link-clicks.ts b/apps/web/scripts/sync-link-clicks.ts
new file mode 100644
index 0000000000..10f325707a
--- /dev/null
+++ b/apps/web/scripts/sync-link-clicks.ts
@@ -0,0 +1,65 @@
+import "dotenv-flow/config";
+import * as Papa from "papaparse";
+import * as fs from "fs";
+import prisma from "@/lib/prisma";
+
+const index = 24000;
+const linkClicks: { domain: string; key: string; clicks: string }[] = [];
+
+async function main() {
+ Papa.parse(fs.createReadStream("sql.csv", "utf-8"), {
+ header: true,
+ step: (result: {
+ data: { domain: string; key: string; clicks: string };
+ }) => {
+ linkClicks.push(result.data);
+ },
+ complete: async () => {
+ const linksWithClicks = await prisma.link.findMany({
+ where: {
+ clicks: {
+ gt: 0,
+ },
+ },
+ select: {
+ domain: true,
+ key: true,
+ },
+ });
+ console.table(linkClicks.slice(0, 50));
+
+ const linkClicksToUpdate = linkClicks
+ .filter((linkClick) => {
+ const { domain, key } = linkClick;
+ return linksWithClicks.find(
+ (link) => link.domain === domain && link.key === key,
+ );
+ })
+ .slice(index, index + 1000);
+
+ await Promise.all(
+ linkClicksToUpdate.map((linkClick) => {
+ const { domain, key, clicks } = linkClick;
+ console.log(`Updating ${domain}/${key} with ${clicks} clicks.`);
+ return prisma.link.update({
+ where: {
+ domain_key: {
+ domain,
+ key,
+ },
+ },
+ data: {
+ clicks: parseInt(clicks),
+ },
+ });
+ }),
+ );
+
+ console.log(
+ `Done updating ${index} to ${index + linkClicksToUpdate.length} links.`,
+ );
+ },
+ });
+}
+
+main();