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;
|
done = true;
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
process(err, ids, function(err) {
|
process(ids, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,7 @@ var async = require('async'),
|
|||||||
module.exports = function(Categories) {
|
module.exports = function(Categories) {
|
||||||
|
|
||||||
Categories.purge = function(cid, callback) {
|
Categories.purge = function(cid, callback) {
|
||||||
batch.processSortedSet('categories:' + cid + ':tid', function(err, tids, next) {
|
batch.processSortedSet('categories:' + cid + ':tid', function(tids, next) {
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
async.eachLimit(tids, 10, function(tid, next) {
|
async.eachLimit(tids, 10, function(tid, next) {
|
||||||
threadTools.purge(tid, 0, next);
|
threadTools.purge(tid, 0, next);
|
||||||
}, next);
|
}, next);
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ var winston = require('winston'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
ThreadTools.purge = function(tid, uid, callback) {
|
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);
|
async.eachLimit(pids, 10, posts.purge, next);
|
||||||
}, {alwaysStartAt: 0}, function(err) {
|
}, {alwaysStartAt: 0}, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -34,11 +34,7 @@ module.exports = function(User) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function deleteSortedSetElements(set, deleteMethod, callback) {
|
function deleteSortedSetElements(set, deleteMethod, callback) {
|
||||||
batch.processSortedSet(set, function(err, ids, next) {
|
batch.processSortedSet(set, function(ids, next) {
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
async.eachLimit(ids, 10, deleteMethod, next);
|
async.eachLimit(ids, 10, deleteMethod, next);
|
||||||
}, {alwaysStartAt: 0}, callback);
|
}, {alwaysStartAt: 0}, callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ var db = require('../database'),
|
|||||||
user = require('../user'),
|
user = require('../user'),
|
||||||
topics = require('../topics'),
|
topics = require('../topics'),
|
||||||
emailer = require('../emailer'),
|
emailer = require('../emailer'),
|
||||||
meta = require('../meta');
|
meta = require('../meta'),
|
||||||
|
batch = require('../batch');
|
||||||
|
|
||||||
module.exports = function(User) {
|
module.exports = function(User) {
|
||||||
User.startJobs = function() {
|
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.');
|
return winston.log('[user/jobs] Did not send daily digests because subscription system is disabled.');
|
||||||
}
|
}
|
||||||
|
|
||||||
async.parallel({
|
topics.getLatestTopics(0, 0, 10, 'day', function(err, topics) {
|
||||||
recent: function(next) {
|
|
||||||
topics.getLatestTopics(0, 0, 10, 'day', next);
|
|
||||||
},
|
|
||||||
uids: function(next) {
|
|
||||||
db.getSortedSetRange('users:joindate', 0, -1, next);
|
|
||||||
}
|
|
||||||
}, function(err, data) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return winston.error('[user/jobs] Could not send daily digests: ' + err.message);
|
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) {
|
if (err) {
|
||||||
return winston.error('[user/jobs] Could not send daily digests: ' + err.message);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var subscribed = userSettings.filter(function(setting) {
|
var subscribed = userSettings.filter(function(setting) {
|
||||||
@@ -50,19 +45,31 @@ module.exports = function(User) {
|
|||||||
return setting.uid;
|
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();
|
var now = new Date();
|
||||||
|
|
||||||
User.getMultipleUserFields(uids, ['uid', 'username', 'lastonline'], function(err, users) {
|
User.getMultipleUserFields(uids, ['uid', 'username', 'lastonline'], function(err, users) {
|
||||||
if (err) {
|
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) {
|
async.eachLimit(users, 100, function(userObj, next) {
|
||||||
user.notifications.getDailyUnread(userObj.uid, function(err, notifications) {
|
user.notifications.getDailyUnread(userObj.uid, function(err, notifications) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -70,18 +77,14 @@ module.exports = function(User) {
|
|||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove expired notifications
|
|
||||||
notifications = notifications.filter(Boolean);
|
notifications = notifications.filter(Boolean);
|
||||||
|
|
||||||
// Turn relative URLs into absolute ones
|
|
||||||
for(var i=0; i<notifications.length; ++i) {
|
for(var i=0; i<notifications.length; ++i) {
|
||||||
if (notifications[i].image.indexOf('http') !== 0) {
|
if (notifications[i].image.indexOf('http') !== 0) {
|
||||||
notifications[i].image = nconf.get('url') + notifications[i].image;
|
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, {
|
emailer.send('dailydigest', userObj.uid, {
|
||||||
subject: '[' + meta.config.title + '] Daily Digest for ' + now.getFullYear()+ '/' + (now.getMonth()+1) + '/' + now.getDate(),
|
subject: '[' + meta.config.title + '] Daily Digest for ' + now.getFullYear()+ '/' + (now.getMonth()+1) + '/' + now.getDate(),
|
||||||
username: userObj.username,
|
username: userObj.username,
|
||||||
@@ -93,14 +96,7 @@ module.exports = function(User) {
|
|||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
}, function(err) {
|
}, callback);
|
||||||
// When finished...
|
|
||||||
if (!err) {
|
|
||||||
winston.info('[user/jobs] Daily Digests sent!');
|
|
||||||
} else {
|
|
||||||
winston.error('[user/jobs] Could not send daily digests: ' + err.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user