notification changes

-only send a notification when the person you follow creates a topic
-you still get a notification per post if you are following a topic
-changed notifications.push so that it sends the notifications over a
period of time, currently to 50 users per second
-optimized topics.notifyFollowers and
user.notifications.sendTopicNotification, they no longer query the
database for the topic and post data instead they get it as params
-you can no longer follow yourself :)
-changed mongo sortedSetRemove so that it doesn't use $in if there is
only a single value to remove
This commit is contained in:
barisusakli
2014-10-15 21:55:31 -04:00
parent eb546dfaab
commit 9e8be432b3
7 changed files with 98 additions and 86 deletions

View File

@@ -128,17 +128,58 @@ var async = require('async'),
return callback();
}
var websockets = require('./socket.io');
if (!Array.isArray(uids)) {
uids = [uids];
}
uids = uids.filter(function(uid) {
return parseInt(uid, 10);
});
if (!uids.length) {
return callback();
}
var done = false;
var start = 0;
var batchSize = 50;
setTimeout(function() {
async.whilst(
function() {
return !done;
},
function(next) {
var currentUids = uids.slice(start, start + batchSize);
if (!currentUids.length) {
done = true;
return next();
}
pushToUids(currentUids, notification, function(err) {
if (err) {
return next(err);
}
start = start + batchSize;
setTimeout(next, 1000);
});
},
function(err) {
if (err) {
winston.error(err.stack);
}
}
);
}, 1000);
callback();
};
function pushToUids(uids, notification, callback) {
var unreadKeys = [];
var readKeys = [];
uids.filter(function(uid) {
return parseInt(uid, 10);
}).forEach(function(uid) {
uids.forEach(function(uid) {
unreadKeys.push('uid:' + uid + ':notifications:unread');
readKeys.push('uid:' + uid + ':notifications:read');
});
@@ -163,13 +204,15 @@ var async = require('async'),
}
plugins.fireHook('action:notification.pushed', {notification: notification, uids: uids});
callback();
var websockets = require('./socket.io');
for(var i=0; i<uids.length; ++i) {
websockets.in('uid_' + uids[i]).emit('event:new_notification', notification);
}
callback();
});
};
}
Notifications.pushGroup = function(notification, groupName, callback) {
callback = callback || function() {};