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.

use while loop

Steven Teyf0ac659636d1
diff --git a/apps/web/scripts/misc/disable-workspace-links.ts b/apps/web/scripts/misc/disable-workspace-links.ts
index 00514d1336..96c01fa8df 100644
--- a/apps/web/scripts/misc/disable-workspace-links.ts
+++ b/apps/web/scripts/misc/disable-workspace-links.ts
@@ -29,29 +29,36 @@ async function main() {
return;
}
- const linksToDisable = await prisma.link.findMany({
- where: {
- projectId: project.id,
- disabledAt: null,
- },
- });
-
- if (linksToDisable.length > 0) {
- const disabledLinks = await prisma.link.updateMany({
+ while (true) {
+ const linksToDisable = await prisma.link.findMany({
where: {
- id: {
- in: linksToDisable.map((link) => link.id),
- },
- },
- data: {
- disabledAt: new Date(),
+ projectId: project.id,
+ disabledAt: null,
},
+ take: 100,
});
+ if (linksToDisable.length === 0) {
+ console.log("No more links to disable. Exiting...");
+ break;
+ }
+
+ if (linksToDisable.length > 0) {
+ const disabledLinks = await prisma.link.updateMany({
+ where: {
+ id: {
+ in: linksToDisable.map((link) => link.id),
+ },
+ },
+ data: {
+ disabledAt: new Date(),
+ },
+ });
- console.log(`Disabled ${disabledLinks.count} links`);
+ console.log(`Disabled ${disabledLinks.count} links`);
- const res = await linkCache.expireMany(linksToDisable);
- console.log(res);
+ const res = await linkCache.expireMany(linksToDisable);
+ console.log(res);
+ }
}
const userToBan = project.users[0].user;
diff --git a/apps/web/scripts/misc/restore-workspace-access.ts b/apps/web/scripts/misc/restore-workspace-access.ts
index b208ff48b9..9fc615dced 100644
--- a/apps/web/scripts/misc/restore-workspace-access.ts
+++ b/apps/web/scripts/misc/restore-workspace-access.ts
@@ -17,31 +17,38 @@ async function main() {
},
});
- const linksToRestore = await prisma.link.findMany({
- where: {
- projectId: project.id,
- disabledAt: {
- not: null,
- },
- },
- });
-
- if (linksToRestore.length > 0) {
- const restoredLinks = await prisma.link.updateMany({
+ while (true) {
+ const linksToRestore = await prisma.link.findMany({
where: {
- id: {
- in: linksToRestore.map((link) => link.id),
+ projectId: project.id,
+ disabledAt: {
+ not: null,
},
},
- data: {
- disabledAt: null,
- },
+ take: 100,
});
+ if (linksToRestore.length === 0) {
+ console.log("No more links to restore. Exiting...");
+ break;
+ }
+
+ if (linksToRestore.length > 0) {
+ const restoredLinks = await prisma.link.updateMany({
+ where: {
+ id: {
+ in: linksToRestore.map((link) => link.id),
+ },
+ },
+ data: {
+ disabledAt: null,
+ },
+ });
- console.log(`Restored ${restoredLinks.count} links`);
+ console.log(`Restored ${restoredLinks.count} links`);
- const res = await linkCache.expireMany(linksToRestore);
- console.log(res);
+ const res = await linkCache.expireMany(linksToRestore);
+ console.log(res);
+ }
}
await prisma.projectUsers.update({