From e309ac50408f18bbea583e4f7d3af829a0c2b0af Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 6 Jul 2017 15:42:37 -0400 Subject: [PATCH] fixes #5790 --- src/topics/recent.js | 2 +- src/upgrades/1.5.2/rss_token_wipe.js | 2 +- src/user/digest.js | 64 ++++++++++++++-------------- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/topics/recent.js b/src/topics/recent.js index b2e0de6023..b2a9d28a63 100644 --- a/src/topics/recent.js +++ b/src/topics/recent.js @@ -90,7 +90,7 @@ module.exports = function (Topics) { ], callback); } - + /* not an orphan method, used in widget-essentials */ Topics.getLatestTopics = function (uid, start, stop, term, callback) { async.waterfall([ function (next) { diff --git a/src/upgrades/1.5.2/rss_token_wipe.js b/src/upgrades/1.5.2/rss_token_wipe.js index c133bcd01c..2bfa9cd02b 100644 --- a/src/upgrades/1.5.2/rss_token_wipe.js +++ b/src/upgrades/1.5.2/rss_token_wipe.js @@ -11,7 +11,7 @@ module.exports = { var progress = this.progress; batch.processSortedSet('users:joindate', function (uids, next) { - async.eachSeries(uids, function (uid, next) { + async.eachLimit(uids, 500, function (uid, next) { progress.incr(); db.deleteObjectField('user:' + uid, 'rss_token', next); }, next); diff --git a/src/user/digest.js b/src/user/digest.js index b9cb689622..0c58d7e3e1 100644 --- a/src/user/digest.js +++ b/src/user/digest.js @@ -26,41 +26,29 @@ Digest.execute = function (payload, callback) { var subscribers; async.waterfall([ function (next) { - async.parallel({ - topics: async.apply(topics.getLatestTopics, 0, 0, 9, payload.interval), - subscribers: function (next) { - if (payload.subscribers) { - setImmediate(next, undefined, payload.subscribers); - } else { - Digest.getSubscribers(payload.interval, next); - } - }, - }, next); + if (payload.subscribers) { + setImmediate(next, undefined, payload.subscribers); + } else { + Digest.getSubscribers(payload.interval, next); + } }, - function (data, next) { - subscribers = data.subscribers; - if (!data.subscribers.length) { + function (subscribers, next) { + if (!subscribers.length) { return callback(); } - // Fix relative paths in topic data - data.topics.topics = data.topics.topics.map(function (topicObj) { - var user = topicObj.hasOwnProperty('teaser') && topicObj.teaser !== undefined ? topicObj.teaser.user : topicObj.user; - if (user && user.picture && utils.isRelativeUrl(user.picture)) { - user.picture = nconf.get('base_url') + user.picture; - } - - return topicObj; - }); + var data = { + interval: payload.interval, + subscribers: subscribers, + }; - data.interval = payload.interval; Digest.send(data, next); }, - ], function (err) { + ], function (err, count) { if (err) { winston.error('[user/jobs] Could not send digests (' + payload.interval + '): ' + err.message); } else { - winston.info('[user/jobs] Digest (' + payload.interval + ') scheduling completed. ' + subscribers.length + ' email(s) sent.'); + winston.info('[user/jobs] Digest (' + payload.interval + ') scheduling completed. ' + count + ' email(s) sent.'); } callback(err); @@ -116,12 +104,16 @@ Digest.send = function (data, callback) { async.eachLimit(users, 100, function (userObj, next) { async.waterfall([ function (next) { - user.notifications.getDailyUnread(userObj.uid, next); + async.parallel({ + notifications: async.apply(user.notifications.getDailyUnread, userObj.uid), + topics: async.apply(topics.getPopular, data.interval, userObj.uid, 10), + }, next); }, - function (notifications, next) { - notifications = notifications.filter(Boolean); + function (data, next) { + var notifications = data.notifications.filter(Boolean); + // If there are no notifications and no new topics, don't bother sending a digest - if (!notifications.length && !data.topics.topics.length) { + if (!notifications.length && !data.topics.length) { return next(); } @@ -131,6 +123,16 @@ Digest.send = function (data, callback) { } }); + // Fix relative paths in topic data + data.topics = data.topics.map(function (topicObj) { + var user = topicObj.hasOwnProperty('teaser') && topicObj.teaser !== undefined ? topicObj.teaser.user : topicObj.user; + if (user && user.picture && utils.isRelativeUrl(user.picture)) { + user.picture = nconf.get('base_url') + user.picture; + } + + return topicObj; + }); + emailer.send('digest', userObj.uid, { subject: '[' + meta.config.title + '] [[email:digest.subject, ' + (now.getFullYear() + '/' + (now.getMonth() + 1) + '/' + now.getDate()) + ']]', username: userObj.username, @@ -138,7 +140,7 @@ Digest.send = function (data, callback) { url: nconf.get('url'), site_title: meta.config.title || meta.config.browserTitle || 'NodeBB', notifications: notifications, - recent: data.topics.topics, + recent: data.topics, interval: data.interval, }); next(); @@ -147,6 +149,6 @@ Digest.send = function (data, callback) { }, next); }, ], function (err) { - callback(err); + callback(err, data.subscribers.length); }); };