mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 14:05:46 +01:00
use processSortedSet instead of getting all users
This commit is contained in:
@@ -44,7 +44,7 @@ var async = require('async'),
|
||||
done = true;
|
||||
return next();
|
||||
}
|
||||
process(err, ids, function(err) {
|
||||
process(ids, function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
@@ -9,11 +9,7 @@ var async = require('async'),
|
||||
module.exports = function(Categories) {
|
||||
|
||||
Categories.purge = function(cid, callback) {
|
||||
batch.processSortedSet('categories:' + cid + ':tid', function(err, tids, next) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
batch.processSortedSet('categories:' + cid + ':tid', function(tids, next) {
|
||||
async.eachLimit(tids, 10, function(tid, next) {
|
||||
threadTools.purge(tid, 0, next);
|
||||
}, next);
|
||||
|
||||
@@ -72,7 +72,7 @@ var winston = require('winston'),
|
||||
}
|
||||
|
||||
ThreadTools.purge = function(tid, uid, callback) {
|
||||
batch.processSortedSet('tid:' + tid + ':posts', function(err, pids, next) {
|
||||
batch.processSortedSet('tid:' + tid + ':posts', function(pids, next) {
|
||||
async.eachLimit(pids, 10, posts.purge, next);
|
||||
}, {alwaysStartAt: 0}, function(err) {
|
||||
if (err) {
|
||||
|
||||
@@ -34,11 +34,7 @@ module.exports = function(User) {
|
||||
}
|
||||
|
||||
function deleteSortedSetElements(set, deleteMethod, callback) {
|
||||
batch.processSortedSet(set, function(err, ids, next) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
batch.processSortedSet(set, function(ids, next) {
|
||||
async.eachLimit(ids, 10, deleteMethod, next);
|
||||
}, {alwaysStartAt: 0}, callback);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ var db = require('../database'),
|
||||
user = require('../user'),
|
||||
topics = require('../topics'),
|
||||
emailer = require('../emailer'),
|
||||
meta = require('../meta');
|
||||
meta = require('../meta'),
|
||||
batch = require('../batch');
|
||||
|
||||
module.exports = function(User) {
|
||||
User.startJobs = function() {
|
||||
@@ -27,21 +28,15 @@ module.exports = function(User) {
|
||||
return winston.log('[user/jobs] Did not send daily digests because subscription system is disabled.');
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
recent: function(next) {
|
||||
topics.getLatestTopics(0, 0, 10, 'day', next);
|
||||
},
|
||||
uids: function(next) {
|
||||
db.getSortedSetRange('users:joindate', 0, -1, next);
|
||||
}
|
||||
}, function(err, data) {
|
||||
topics.getLatestTopics(0, 0, 10, 'day', function(err, topics) {
|
||||
if (err) {
|
||||
return winston.error('[user/jobs] Could not send daily digests: ' + err.message);
|
||||
}
|
||||
|
||||
User.getMultipleUserSettings(data.uids, function(err, userSettings) {
|
||||
batch.processSortedSet('users:joindate', function(uids, next) {
|
||||
User.getMultipleUserSettings(uids, function(err, userSettings) {
|
||||
if (err) {
|
||||
return winston.error('[user/jobs] Could not send daily digests: ' + err.message);
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var subscribed = userSettings.filter(function(setting) {
|
||||
@@ -50,19 +45,31 @@ module.exports = function(User) {
|
||||
return setting.uid;
|
||||
});
|
||||
|
||||
sendEmails(subscribed, data.recent.topics);
|
||||
if (!subscribed.length) {
|
||||
return next();
|
||||
}
|
||||
|
||||
sendEmails(subscribed, topics, next);
|
||||
});
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
winston.error('[user/jobs] Could not send daily digests: ' + err.message);
|
||||
} else {
|
||||
winston.info('[user/jobs] Daily Digests sent!');
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function sendEmails(uids, recentTopics) {
|
||||
function sendEmails(uids, recentTopics, callback) {
|
||||
var now = new Date();
|
||||
|
||||
User.getMultipleUserFields(uids, ['uid', 'username', 'lastonline'], function(err, users) {
|
||||
if (err) {
|
||||
return winston.error('[user/jobs] Could not send daily digests: ' + err.message);
|
||||
winston.error('[user/jobs] Could not send daily digests: ' + err.message);
|
||||
return callback(err);
|
||||
}
|
||||
// Consider using eachLimit, but *only* if people complain about email relays choking -- otherwise we're ok.
|
||||
|
||||
async.eachLimit(users, 100, function(userObj, next) {
|
||||
user.notifications.getDailyUnread(userObj.uid, function(err, notifications) {
|
||||
if (err) {
|
||||
@@ -70,18 +77,14 @@ module.exports = function(User) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
// Remove expired notifications
|
||||
notifications = notifications.filter(Boolean);
|
||||
|
||||
// Turn relative URLs into absolute ones
|
||||
for(var i=0; i<notifications.length; ++i) {
|
||||
if (notifications[i].image.indexOf('http') !== 0) {
|
||||
notifications[i].image = nconf.get('url') + notifications[i].image;
|
||||
}
|
||||
}
|
||||
|
||||
// Send daily digest email
|
||||
// winston.info('[user/notifications] Sending Daily Digest to uid ' + userObj.uid);
|
||||
emailer.send('dailydigest', userObj.uid, {
|
||||
subject: '[' + meta.config.title + '] Daily Digest for ' + now.getFullYear()+ '/' + (now.getMonth()+1) + '/' + now.getDate(),
|
||||
username: userObj.username,
|
||||
@@ -93,14 +96,7 @@ module.exports = function(User) {
|
||||
|
||||
next();
|
||||
});
|
||||
}, function(err) {
|
||||
// When finished...
|
||||
if (!err) {
|
||||
winston.info('[user/jobs] Daily Digests sent!');
|
||||
} else {
|
||||
winston.error('[user/jobs] Could not send daily digests: ' + err.message);
|
||||
}
|
||||
});
|
||||
}, callback);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user