fix: closes #13258, dont mark digest as delivered if it fails

show fail count and sent count separately
This commit is contained in:
Barış Soner Uşaklı
2026-01-22 11:31:59 -05:00
parent 3272ea576f
commit f29c9f064b

View File

@@ -84,6 +84,7 @@ Digest.getSubscribers = async function (interval) {
Digest.send = async function (data) { Digest.send = async function (data) {
let emailsSent = 0; let emailsSent = 0;
let emailsFailed = 0;
if (!data || !data.subscribers || !data.subscribers.length) { if (!data || !data.subscribers || !data.subscribers.length) {
return emailsSent; return emailsSent;
} }
@@ -100,6 +101,7 @@ Digest.send = async function (data) {
return; return;
} }
const userSettings = await user.getMultipleUserSettings(userData.map(u => u.uid)); const userSettings = await user.getMultipleUserSettings(userData.map(u => u.uid));
const successfullUids = [];
await Promise.all(userData.map(async (userObj, index) => { await Promise.all(userData.map(async (userObj, index) => {
const userSetting = userSettings[index]; const userSetting = userSettings[index];
const [publicRooms, notifications, topics] = await Promise.all([ const [publicRooms, notifications, topics] = await Promise.all([
@@ -124,34 +126,39 @@ Digest.send = async function (data) {
} }
}); });
emailsSent += 1; try {
await emailer.send('digest', userObj.uid, { await emailer.send('digest', userObj.uid, {
subject: `[[email:digest.subject, ${date.toLocaleDateString(userSetting.userLang)}]]`, subject: `[[email:digest.subject, ${date.toLocaleDateString(userSetting.userLang)}]]`,
username: userObj.username, username: userObj.username,
userslug: userObj.userslug, userslug: userObj.userslug,
notifications: unreadNotifs, notifications: unreadNotifs,
publicRooms: publicRooms, publicRooms: publicRooms,
recent: topics.recent, recent: topics.recent,
topTopics: topics.top, topTopics: topics.top,
popularTopics: topics.popular, popularTopics: topics.popular,
interval: data.interval, interval: data.interval,
showUnsubscribe: true, showUnsubscribe: true,
}).catch((err) => { });
emailsSent += 1;
successfullUids.push(userObj.uid);
} catch (err) {
emailsFailed += 1;
if (!errorLogged) { if (!errorLogged) {
winston.error(`[user/jobs] Could not send digest email\n[emailer.send] ${err.stack}`); winston.error(`[user/jobs] Could not send digest email\n[emailer.send] ${err.stack}`);
errorLogged = true; errorLogged = true;
} }
}); }
})); }));
if (data.interval !== 'alltime') {
if (data.interval !== 'alltime' && successfullUids.length) {
const now = Date.now(); const now = Date.now();
await db.sortedSetAdd('digest:delivery', userData.map(() => now), userData.map(u => u.uid)); await db.sortedSetAdd('digest:delivery', successfullUids.map(() => now), successfullUids);
} }
}, { }, {
interval: 1000, interval: 1000,
batch: 100, batch: 100,
}); });
winston.info(`[user/jobs] Digest (${data.interval}) sending completed. ${emailsSent} emails sent.`); winston.info(`[user/jobs] Digest (${data.interval}) sending completed. ${emailsSent} emails sent. ${emailsFailed} failures.`);
return emailsSent; return emailsSent;
}; };