removed users:online set

using websockets.getConnectedClients directly
v1.18.x
barisusakli 10 years ago
parent 129a438ebe
commit 40fe40deac

@ -15,7 +15,7 @@ usersController.getOnlineUsers = function(req, res, next) {
user.getUsersFromSet('users:online', 0, 49, next); user.getUsersFromSet('users:online', 0, 49, next);
}, },
count: function(next) { count: function(next) {
db.sortedSetCard('users:online', next); next(null, websockets.getConnectedClients().length);
}, },
isAdministrator: function(next) { isAdministrator: function(next) {
user.isAdministrator(uid, next); user.isAdministrator(uid, next);

@ -98,8 +98,6 @@ Sockets.init = function(server) {
Sockets.server = io; Sockets.server = io;
db.delete('users:online');
fs.readdir(__dirname, function(err, files) { fs.readdir(__dirname, function(err, files) {
files.splice(files.indexOf('index.js'), 1); files.splice(files.indexOf('index.js'), 1);
@ -140,7 +138,7 @@ Sockets.init = function(server) {
if (uid) { if (uid) {
socket.join('uid_' + uid); socket.join('uid_' + uid);
socket.join('online_users'); socket.join('online_users');
db.sortedSetAdd('users:online', Date.now(), uid, function(err) {
async.parallel({ async.parallel({
user: function(next) { user: function(next) {
user.getUserFields(uid, ['username', 'userslug', 'picture', 'status'], next); user.getUserFields(uid, ['username', 'userslug', 'picture', 'status'], next);
@ -163,7 +161,7 @@ Sockets.init = function(server) {
socket.broadcast.emit('event:user_status_change', {uid:uid, status: userData.user.status}); socket.broadcast.emit('event:user_status_change', {uid:uid, status: userData.user.status});
}); });
});
} else { } else {
socket.join('online_guests'); socket.join('online_guests');
socket.emit('event:connect', { socket.emit('event:connect', {
@ -179,12 +177,7 @@ Sockets.init = function(server) {
socket.on('disconnect', function() { socket.on('disconnect', function() {
var socketCount = Sockets.getUserSocketCount(uid); var socketCount = Sockets.getUserSocketCount(uid);
if (uid && socketCount <= 1) { if (uid && socketCount <= 1) {
db.sortedSetRemove('users:online', uid, function(err) {
if (err) {
return winston.error(err.message);
}
socket.broadcast.emit('event:user_status_change', {uid: uid, status: 'offline'}); socket.broadcast.emit('event:user_status_change', {uid: uid, status: 'offline'});
});
} }
onUserDisconnect(uid, socket.id, socketCount); onUserDisconnect(uid, socket.id, socketCount);

@ -230,7 +230,12 @@ var async = require('async'),
User.getUsersFromSet = function(set, start, stop, callback) { User.getUsersFromSet = function(set, start, stop, callback) {
async.waterfall([ async.waterfall([
function(next) { function(next) {
if (set === 'users:online') {
var uids = require('./socket.io').getConnectedClients();
next(null, uids.slice(start, stop + 1));
} else {
db.getSortedSetRevRange(set, start, stop, next); db.getSortedSetRevRange(set, start, stop, next);
}
}, },
function(uids, next) { function(uids, next) {
User.getUsers(uids, next); User.getUsers(uids, next);
@ -247,7 +252,7 @@ var async = require('async'),
User.isAdministrator(uids, next); User.isAdministrator(uids, next);
}, },
isOnline: function(next) { isOnline: function(next) {
db.isSortedSetMembers('users:online', uids, next); require('./socket.io').isUsersOnline(uids, next);
} }
}, function(err, results) { }, function(err, results) {
if (err) { if (err) {

Loading…
Cancel
Save