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.

Update send-batch-emails.ts

Steven Tey20da486582c0
diff --git a/apps/web/scripts/send-batch-emails.ts b/apps/web/scripts/send-batch-emails.ts
index a7660a0e69..97330e6434 100644
--- a/apps/web/scripts/send-batch-emails.ts
+++ b/apps/web/scripts/send-batch-emails.ts
@@ -1,50 +1,60 @@
import ConnectPlatformsReminder from "@dub/email/templates/connect-platforms-reminder";
import { prisma } from "@dub/prisma";
+import { chunk } from "@dub/utils";
import "dotenv-flow/config";
import { queueBatchEmail } from "../lib/email/queue-batch-email";
import { generateUnsubscribeToken } from "../lib/email/unsubscribe-token";
async function main() {
- const usersToNotify = await prisma.user.findMany({
- where: {
- sentMail: false,
- notificationPreferences: {
- partnerAccount: true,
+ while (true) {
+ const usersToNotify = await prisma.user.findMany({
+ where: {
+ sentMail: false,
+ notificationPreferences: {
+ partnerAccount: true,
+ },
+ partners: {
+ some: {},
+ },
},
- partners: {
- some: {},
- },
- },
- take: 1000,
- });
- console.log(`Found ${usersToNotify.length} users to notify`);
+ take: 10000,
+ });
+ if (usersToNotify.length === 0) {
+ console.log("No more users to notify");
+ break;
+ }
+ console.log(`Found ${usersToNotify.length} users to notify`);
- const res = await queueBatchEmail<typeof ConnectPlatformsReminder>(
- usersToNotify.map((user) => ({
- to: user.email!,
- subject: "Verify your social platforms on Dub Partners",
- variant: "marketing",
- templateName: "ConnectPlatformsReminder",
- templateProps: {
- email: user.email!,
- unsubscribeUrl: `https://partners.dub.co/unsubscribe/${generateUnsubscribeToken(user.email!)}`,
- },
- })),
- );
+ const res = await queueBatchEmail<typeof ConnectPlatformsReminder>(
+ usersToNotify.map((user) => ({
+ to: user.email!,
+ subject: "Verify your social platforms on Dub Partners",
+ variant: "marketing",
+ templateName: "ConnectPlatformsReminder",
+ templateProps: {
+ email: user.email!,
+ unsubscribeUrl: `https://partners.dub.co/unsubscribe/${generateUnsubscribeToken(user.email!)}`,
+ },
+ })),
+ );
- console.log(res);
+ console.log(res);
- const updatedUsers = await prisma.user.updateMany({
- where: {
- id: {
- in: usersToNotify.map((user) => user.id),
- },
- },
- data: {
- sentMail: true,
- },
- });
- console.log(`Updated ${updatedUsers.count} users to sentMail: true`);
+ const chunkedUsers = chunk(usersToNotify, 1000);
+ for (const cu of chunkedUsers) {
+ const res = await prisma.user.updateMany({
+ where: {
+ id: {
+ in: cu.map((u) => u.id),
+ },
+ },
+ data: {
+ sentMail: true,
+ },
+ });
+ console.log(`Updated ${res.count} users to sentMail: true`);
+ }
+ }
}
main();