Skip to content

Node.js based forum software built for the modern web

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

Barış Soner Uşaklıf29c9f064b93
diff --git a/src/user/digest.js b/src/user/digest.js
index 77bc2e93e5..ae71856cec 100644
--- a/src/user/digest.js
+++ b/src/user/digest.js
@@ -84,6 +84,7 @@ Digest.getSubscribers = async function (interval) {
Digest.send = async function (data) {
let emailsSent = 0;
+ let emailsFailed = 0;
if (!data || !data.subscribers || !data.subscribers.length) {
return emailsSent;
}
@@ -100,6 +101,7 @@ Digest.send = async function (data) {
return;
}
const userSettings = await user.getMultipleUserSettings(userData.map(u => u.uid));
+ const successfullUids = [];
await Promise.all(userData.map(async (userObj, index) => {
const userSetting = userSettings[index];
const [publicRooms, notifications, topics] = await Promise.all([
@@ -124,34 +126,39 @@ Digest.send = async function (data) {
}
});
- emailsSent += 1;
- await emailer.send('digest', userObj.uid, {
- subject: `[[email:digest.subject, ${date.toLocaleDateString(userSetting.userLang)}]]`,
- username: userObj.username,
- userslug: userObj.userslug,
- notifications: unreadNotifs,
- publicRooms: publicRooms,
- recent: topics.recent,
- topTopics: topics.top,
- popularTopics: topics.popular,
- interval: data.interval,
- showUnsubscribe: true,
- }).catch((err) => {
+ try {
+ await emailer.send('digest', userObj.uid, {
+ subject: `[[email:digest.subject, ${date.toLocaleDateString(userSetting.userLang)}]]`,
+ username: userObj.username,
+ userslug: userObj.userslug,
+ notifications: unreadNotifs,
+ publicRooms: publicRooms,
+ recent: topics.recent,
+ topTopics: topics.top,
+ popularTopics: topics.popular,
+ interval: data.interval,
+ showUnsubscribe: true,
+ });
+ emailsSent += 1;
+ successfullUids.push(userObj.uid);
+ } catch (err) {
+ emailsFailed += 1;
if (!errorLogged) {
winston.error(`[user/jobs] Could not send digest email\n[emailer.send] ${err.stack}`);
errorLogged = true;
}
- });
+ }
}));
- if (data.interval !== 'alltime') {
+
+ if (data.interval !== 'alltime' && successfullUids.length) {
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,
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;
};