v1.18.x
Julian Lam 8 years ago
parent 77d6181bd1
commit e309ac5040

@ -90,7 +90,7 @@ module.exports = function (Topics) {
], callback); ], callback);
} }
/* not an orphan method, used in widget-essentials */
Topics.getLatestTopics = function (uid, start, stop, term, callback) { Topics.getLatestTopics = function (uid, start, stop, term, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {

@ -11,7 +11,7 @@ module.exports = {
var progress = this.progress; var progress = this.progress;
batch.processSortedSet('users:joindate', function (uids, next) { batch.processSortedSet('users:joindate', function (uids, next) {
async.eachSeries(uids, function (uid, next) { async.eachLimit(uids, 500, function (uid, next) {
progress.incr(); progress.incr();
db.deleteObjectField('user:' + uid, 'rss_token', next); db.deleteObjectField('user:' + uid, 'rss_token', next);
}, next); }, next);

@ -26,41 +26,29 @@ Digest.execute = function (payload, callback) {
var subscribers; var subscribers;
async.waterfall([ async.waterfall([
function (next) { function (next) {
async.parallel({
topics: async.apply(topics.getLatestTopics, 0, 0, 9, payload.interval),
subscribers: function (next) {
if (payload.subscribers) { if (payload.subscribers) {
setImmediate(next, undefined, payload.subscribers); setImmediate(next, undefined, payload.subscribers);
} else { } else {
Digest.getSubscribers(payload.interval, next); Digest.getSubscribers(payload.interval, next);
} }
}, },
}, next); function (subscribers, next) {
}, if (!subscribers.length) {
function (data, next) {
subscribers = data.subscribers;
if (!data.subscribers.length) {
return callback(); return callback();
} }
// Fix relative paths in topic data var data = {
data.topics.topics = data.topics.topics.map(function (topicObj) { interval: payload.interval,
var user = topicObj.hasOwnProperty('teaser') && topicObj.teaser !== undefined ? topicObj.teaser.user : topicObj.user; subscribers: subscribers,
if (user && user.picture && utils.isRelativeUrl(user.picture)) { };
user.picture = nconf.get('base_url') + user.picture;
}
return topicObj;
});
data.interval = payload.interval;
Digest.send(data, next); Digest.send(data, next);
}, },
], function (err) { ], function (err, count) {
if (err) { if (err) {
winston.error('[user/jobs] Could not send digests (' + payload.interval + '): ' + err.message); winston.error('[user/jobs] Could not send digests (' + payload.interval + '): ' + err.message);
} else { } 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); callback(err);
@ -116,12 +104,16 @@ Digest.send = function (data, callback) {
async.eachLimit(users, 100, function (userObj, next) { async.eachLimit(users, 100, function (userObj, next) {
async.waterfall([ async.waterfall([
function (next) { 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) { function (data, next) {
notifications = notifications.filter(Boolean); var notifications = data.notifications.filter(Boolean);
// If there are no notifications and no new topics, don't bother sending a digest // 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(); 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, { emailer.send('digest', userObj.uid, {
subject: '[' + meta.config.title + '] [[email:digest.subject, ' + (now.getFullYear() + '/' + (now.getMonth() + 1) + '/' + now.getDate()) + ']]', subject: '[' + meta.config.title + '] [[email:digest.subject, ' + (now.getFullYear() + '/' + (now.getMonth() + 1) + '/' + now.getDate()) + ']]',
username: userObj.username, username: userObj.username,
@ -138,7 +140,7 @@ Digest.send = function (data, callback) {
url: nconf.get('url'), url: nconf.get('url'),
site_title: meta.config.title || meta.config.browserTitle || 'NodeBB', site_title: meta.config.title || meta.config.browserTitle || 'NodeBB',
notifications: notifications, notifications: notifications,
recent: data.topics.topics, recent: data.topics,
interval: data.interval, interval: data.interval,
}); });
next(); next();
@ -147,6 +149,6 @@ Digest.send = function (data, callback) {
}, next); }, next);
}, },
], function (err) { ], function (err) {
callback(err); callback(err, data.subscribers.length);
}); });
}; };

Loading…
Cancel
Save