better total-users calculation hopefully

This commit is contained in:
Kasper Rynning-Tønnesen
2018-06-20 14:59:18 +02:00
parent 893e622ba6
commit d5244c5162

View File

@@ -752,6 +752,7 @@ function left_channel(coll, guid, short_id, in_list, socket, change) {
//coll = coll.replace(/ /g,''); //coll = coll.replace(/ /g,'');
db.collection("connected_users").update({"_id": coll}, {$pull: {users: guid}}, function(err, updated) { db.collection("connected_users").update({"_id": coll}, {$pull: {users: guid}}, function(err, updated) {
if(updated.nModified > 0) { if(updated.nModified > 0) {
db.collection("connected_users").update({"_id": "total_users"}, {$pull: {total_users: guid + coll}}, function(err, updated){});
db.collection("connected_users").find({"_id": coll}, function(err, new_doc){ db.collection("connected_users").find({"_id": coll}, function(err, new_doc){
db.collection("frontpage_lists").update({"_id": coll, viewers: {$gt: 0}}, {$inc: {viewers: -1}}, function(err, doc) { db.collection("frontpage_lists").update({"_id": coll, viewers: {$gt: 0}}, {$inc: {viewers: -1}}, function(err, doc) {
db.collection("user_names").find({"guid": guid}, function(err, docs) { db.collection("user_names").find({"guid": guid}, function(err, docs) {
@@ -762,17 +763,17 @@ function left_channel(coll, guid, short_id, in_list, socket, change) {
io.to(coll).emit("viewers", new_doc[0].users.length); io.to(coll).emit("viewers", new_doc[0].users.length);
socket.leave(coll); socket.leave(coll);
}); });
db.collection("connected_users").update({"_id": "total_users"}, {$pull: {total_users: guid + coll}}, function(err, updated){});
if(!change) { if(!change) {
Functions.remove_name_from_db(guid, name); Functions.remove_name_from_db(guid, name);
} }
}); });
} else { } else {
db.collection("connected_users").update({"_id": "offline_users"}, {$pull: {users: guid}}, function(err, updated){ db.collection("connected_users").update({"_id": "offline_users"}, {$pull: {users: guid}}, function(err, updated){
if(updated.nModified > 0) { //if(updated.nModified > 0) {
db.collection("connected_users").update({"_id": "total_users"}, {$pull: {total_users: guid + coll}}, function(err, updated){}); db.collection("connected_users").update({"_id": "total_users"}, {$pull: {total_users: guid + coll}}, function(err, updated){});
} //}
}); });
} }