OpenStock is an open-source alternative to expensive market platforms. Track real-time prices, set personalized alerts, and explore detailed company insights — built openly, for everyone, forever free.
fix(email): stop the re-engagement job from mailing every Kit subscriber
ravixalgorithm3ed6a697a6b2
diff --git a/lib/inngest/functions.ts b/lib/inngest/functions.tsindex f63c0e4..37e8734 100644--- a/lib/inngest/functions.ts+++ b/lib/inngest/functions.ts@@ -99,14 +99,6 @@ export const sendWeeklyNewsSummary = inngest.createFunction(console.log(`📋 Target Audience: Found ${subData.total_subscribers} total subscribers in Kit.`);console.log(`✅ Confirmed (Active) Subscribers receiving email: ${confirmedCount}`);- // Log names/emails for the user to see in Inngest dashboard- if (subscriberList.length > 0) {- console.log('--- Recipient List ---');- subscriberList.forEach((s: any) => {- console.log(`${s.email_address} (${s.first_name || 'No Name'}) - Status: ${s.state}`);- });- console.log('----------------------');- }} catch (e) {console.warn("Could not list subscribers for logging:", e);}@@ -371,12 +363,11 @@ export const checkInactiveUsers = inngest.createFunction(// Step 2: Send Emailsconst results = await step.run('send-reengagement-emails', async () => {- const { kit } = await import("@/lib/kit");const { connectToDatabase } = await import("@/database/mongoose");const mongoose = await connectToDatabase();const db = mongoose.connection.db;- const sent: string[] = [];+ let sent = 0;for (const user of inactiveUsers) {if (!user.email) continue;@@ -475,13 +466,9 @@ export const checkInactiveUsers = inngest.createFunction(// 1. Add tag "Inactive" to user.// 2. (This is too slow for loop).- // CHECK: Is this the test user?- if (user.email === '[email protected]') {- console.log(`🚀 Sending REAL Re-engagement Email to TEST USER: ${user.email}`);- await kit.sendBroadcast(subject, content);- } else {- console.log(`[Re-engagement Mock] Would send to ${user.email}`);- }+ // Not sent. kit.sendBroadcast mails the whole list, so a "test user" send here went to every+ // subscriber. Wire up a 1:1 send (Kit tag + sequence, or nodemailer) before enabling this.+ void subject; void content;// Update DB to avoid loopif (db) {@@ -489,9 +476,9 @@ export const checkInactiveUsers = inngest.createFunction(// @ts-ignoreawait db.collection('user').updateOne({ _id: new mongoose.Types.ObjectId(user.id) }, { $set: { lastReengagementSentAt: new Date() } });}- sent.push(user.email);+ sent++;} catch (e) {- console.error("Failed to process user", user.email, e);+ console.error("Failed to process user", user.id, e);}}return sent;