fix acp high presence topics

v1.18.x
barisusakli 10 years ago
parent 96364935e9
commit cdd5bb5a6e

@ -93,8 +93,7 @@ SocketMeta.rooms.getAll = function(socket, data, callback) {
topics: {} topics: {}
}; };
var scores = {}, var topTenTopics = [],
topTenTopics = [],
tid; tid;
for (var room in roomClients) { for (var room in roomClients) {
@ -104,34 +103,29 @@ SocketMeta.rooms.getAll = function(socket, data, callback) {
var length = roomClients[room].length; var length = roomClients[room].length;
socketData.users.topics += length; socketData.users.topics += length;
if (scores[length]) { topTenTopics.push({tid: tid[1], count: length});
scores[length].push(tid[1]);
} else {
scores[length] = [tid[1]];
}
} else if (room.match(/^category/)) { } else if (room.match(/^category/)) {
socketData.users.category += roomClients[room].length; socketData.users.category += roomClients[room].length;
} }
} }
} }
var scoreKeys = Object.keys(scores), topTenTopics = topTenTopics.sort(function(a, b) {
mostActive = scoreKeys.sort(); return b.count - a.count;
}).slice(0, 10);
while(topTenTopics.length < 10 && mostActive.length > 0) { var topTenTids = topTenTopics.map(function(topic) {
topTenTopics = topTenTopics.concat(scores[mostActive.pop()]); return topic.tid;
} });
topTenTopics = topTenTopics.slice(0, 10);
topics.getTopicsFields(topTenTopics, ['title'], function(err, titles) { topics.getTopicsFields(topTenTids, ['title'], function(err, titles) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
topTenTopics.forEach(function(tid, id) { topTenTopics.forEach(function(topic, index) {
socketData.topics[tid] = { socketData.topics[topic.tid] = {
value: Array.isArray(roomClients['topic_' + tid]) ? roomClients['topic_' + tid].length : 0, value: topic.count || 0,
title: validator.escape(titles[id].title) title: validator.escape(titles[index].title)
}; };
}); });
@ -140,6 +134,4 @@ SocketMeta.rooms.getAll = function(socket, data, callback) {
}; };
/* Exports */
module.exports = SocketMeta; module.exports = SocketMeta;

Loading…
Cancel
Save