|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var os = require('os');
|
|
|
|
|
var nconf = require('nconf');
|
|
|
|
|
var winston = require('winston');
|
|
|
|
@ -68,7 +69,7 @@ SocketRooms.getAll = function (socket, data, callback) {
|
|
|
|
|
category: 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for(var instance in stats) {
|
|
|
|
|
for (var instance in stats) {
|
|
|
|
|
if (stats.hasOwnProperty(instance)) {
|
|
|
|
|
totals.onlineGuestCount += stats[instance].onlineGuestCount;
|
|
|
|
|
totals.onlineRegisteredCount += stats[instance].onlineRegisteredCount;
|
|
|
|
@ -99,30 +100,31 @@ SocketRooms.getAll = function (socket, data, callback) {
|
|
|
|
|
return topic.tid;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
topics.getTopicsFields(topTenTids, ['title'], function (err, titles) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
topics.getTopicsFields(topTenTids, ['title'], next);
|
|
|
|
|
},
|
|
|
|
|
function (titles, next) {
|
|
|
|
|
totals.topics = {};
|
|
|
|
|
topTenTopics.forEach(function (topic, index) {
|
|
|
|
|
totals.topics[topic.tid] = {
|
|
|
|
|
value: topic.count || 0,
|
|
|
|
|
title: validator.escape(String(titles[index].title))
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
next(null, totals);
|
|
|
|
|
}
|
|
|
|
|
totals.topics = {};
|
|
|
|
|
topTenTopics.forEach(function (topic, index) {
|
|
|
|
|
totals.topics[topic.tid] = {
|
|
|
|
|
value: topic.count || 0,
|
|
|
|
|
title: validator.escape(String(titles[index].title))
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback(null, totals);
|
|
|
|
|
});
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketRooms.getOnlineUserCount = function (io) {
|
|
|
|
|
if (!io) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
var count = 0;
|
|
|
|
|
for (var key in io.sockets.adapter.rooms) {
|
|
|
|
|
if (io.sockets.adapter.rooms.hasOwnProperty(key) && key.startsWith('uid_')) {
|
|
|
|
|
++ count;
|
|
|
|
|
|
|
|
|
|
if (io) {
|
|
|
|
|
for (var key in io.sockets.adapter.rooms) {
|
|
|
|
|
if (io.sockets.adapter.rooms.hasOwnProperty(key) && key.startsWith('uid_')) {
|
|
|
|
|
++ count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -132,45 +134,51 @@ SocketRooms.getOnlineUserCount = function (io) {
|
|
|
|
|
SocketRooms.getLocalStats = function (callback) {
|
|
|
|
|
var io = require('../index').server;
|
|
|
|
|
|
|
|
|
|
if (!io) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var roomClients = io.sockets.adapter.rooms;
|
|
|
|
|
var socketData = {
|
|
|
|
|
onlineGuestCount: roomClients.online_guests ? roomClients.online_guests.length : 0,
|
|
|
|
|
onlineRegisteredCount: SocketRooms.getOnlineUserCount(io),
|
|
|
|
|
socketCount: Object.keys(io.sockets.sockets).length,
|
|
|
|
|
onlineGuestCount: 0,
|
|
|
|
|
onlineRegisteredCount: 0,
|
|
|
|
|
socketCount: 0,
|
|
|
|
|
users: {
|
|
|
|
|
categories: roomClients.categories ? roomClients.categories.length : 0,
|
|
|
|
|
recent: roomClients.recent_topics ? roomClients.recent_topics.length : 0,
|
|
|
|
|
unread: roomClients.unread_topics ? roomClients.unread_topics.length : 0,
|
|
|
|
|
categories: 0,
|
|
|
|
|
recent: 0,
|
|
|
|
|
unread: 0,
|
|
|
|
|
topics: 0,
|
|
|
|
|
category: 0
|
|
|
|
|
},
|
|
|
|
|
topics: {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var topTenTopics = [];
|
|
|
|
|
var tid;
|
|
|
|
|
|
|
|
|
|
for (var room in roomClients) {
|
|
|
|
|
if (roomClients.hasOwnProperty(room)) {
|
|
|
|
|
tid = room.match(/^topic_(\d+)/);
|
|
|
|
|
if (tid) {
|
|
|
|
|
socketData.users.topics += roomClients[room].length;
|
|
|
|
|
topTenTopics.push({tid: tid[1], count: roomClients[room].length});
|
|
|
|
|
} else if (room.match(/^category/)) {
|
|
|
|
|
socketData.users.category += roomClients[room].length;
|
|
|
|
|
if (io) {
|
|
|
|
|
var roomClients = io.sockets.adapter.rooms;
|
|
|
|
|
socketData.onlineGuestCount = roomClients.online_guests ? roomClients.online_guests.length : 0;
|
|
|
|
|
socketData.onlineRegisteredCount = SocketRooms.getOnlineUserCount(io);
|
|
|
|
|
socketData.socketCount = Object.keys(io.sockets.sockets).length;
|
|
|
|
|
socketData.users.categories = roomClients.categories ? roomClients.categories.length : 0;
|
|
|
|
|
socketData.users.recent = roomClients.recent_topics ? roomClients.recent_topics.length : 0;
|
|
|
|
|
socketData.users.unread = roomClients.unread_topics ? roomClients.unread_topics.length : 0;
|
|
|
|
|
|
|
|
|
|
var topTenTopics = [];
|
|
|
|
|
var tid;
|
|
|
|
|
|
|
|
|
|
for (var room in roomClients) {
|
|
|
|
|
if (roomClients.hasOwnProperty(room)) {
|
|
|
|
|
tid = room.match(/^topic_(\d+)/);
|
|
|
|
|
if (tid) {
|
|
|
|
|
socketData.users.topics += roomClients[room].length;
|
|
|
|
|
topTenTopics.push({tid: tid[1], count: roomClients[room].length});
|
|
|
|
|
} else if (room.match(/^category/)) {
|
|
|
|
|
socketData.users.category += roomClients[room].length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
topTenTopics = topTenTopics.sort(function (a, b) {
|
|
|
|
|
return b.count - a.count;
|
|
|
|
|
}).slice(0, 10);
|
|
|
|
|
topTenTopics = topTenTopics.sort(function (a, b) {
|
|
|
|
|
return b.count - a.count;
|
|
|
|
|
}).slice(0, 10);
|
|
|
|
|
|
|
|
|
|
socketData.topics = topTenTopics;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
socketData.topics = topTenTopics;
|
|
|
|
|
callback(null, socketData);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|