removed most of the debug

dont get more than 6 usernames for upvote tooltips
generatePostPaths wont check null pids
v1.18.x
barisusakli 11 years ago
parent 0ad42873d5
commit 57e204df8e

@ -14,8 +14,6 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
share.addShareHandlers(topicName); share.addShareHandlers(topicName);
addFavouriteHandler();
addVoteHandler(); addVoteHandler();
}; };
@ -37,12 +35,6 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
}); });
}; };
function addFavouriteHandler() {
$('#post-container').on('mouseenter', '.favourite-tooltip', function() {
loadDataAndCreateTooltip($(this), 'posts.getFavouritedUsers');
});
}
function addVoteHandler() { function addVoteHandler() {
$('#post-container').on('mouseenter', '.post-row .votes', function() { $('#post-container').on('mouseenter', '.post-row .votes', function() {
loadDataAndCreateTooltip($(this), 'posts.getUpvoters'); loadDataAndCreateTooltip($(this), 'posts.getUpvoters');
@ -51,21 +43,21 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com
function loadDataAndCreateTooltip(el, method) { function loadDataAndCreateTooltip(el, method) {
var pid = el.parents('.post-row').attr('data-pid'); var pid = el.parents('.post-row').attr('data-pid');
socket.emit(method, pid, function(err, usernames) { socket.emit(method, pid, function(err, data) {
if (!err) { if (!err) {
createTooltip(el, usernames); createTooltip(el, data);
} }
}); });
} }
function createTooltip(el, usernames) { function createTooltip(el, data) {
var usernames = data.usernames;
if (!usernames.length) { if (!usernames.length) {
return; return;
} }
if (usernames.length > 6) { if (usernames.length + data.otherCount > 6) {
var otherCount = usernames.length - 5; usernames = usernames.join(', ').replace(/,/g, '|');
usernames = usernames.slice(0, 5).join(', ').replace(/,/g, '|'); translator.translate('[[topic:users_and_others, ' + usernames + ', ' + data.otherCount + ']]', function(translated) {
translator.translate('[[topic:users_and_others, ' + usernames + ', ' + otherCount + ']]', function(translated) {
translated = translated.replace(/\|/g, ','); translated = translated.replace(/\|/g, ',');
el.attr('title', translated).tooltip('destroy').tooltip('show'); el.attr('title', translated).tooltip('destroy').tooltip('show');
}); });

@ -109,14 +109,13 @@ var async = require('async'),
}; };
Posts.getPidsFromSet = function(set, start, end, reverse, callback) { Posts.getPidsFromSet = function(set, start, end, reverse, callback) {
if (isNaN(start) || isNaN(end)) {
return callback(null, []);
}
db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, end, callback); db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, end, callback);
}; };
Posts.getPostsByPids = function(pids, callback) { Posts.getPostsByPids = function(pids, callback) {
if (pids && pids.length > 100) {
var e = new Error('getPostsByPids');
winston.warn('[GET_POST_BY_PIDS ' + pids.length, e.stack);
}
var keys = []; var keys = [];
for(var x=0, numPids=pids.length; x<numPids; ++x) { for(var x=0, numPids=pids.length; x<numPids; ++x) {

@ -16,10 +16,6 @@ module.exports = function(privileges) {
privileges.posts = {}; privileges.posts = {};
privileges.posts.get = function(pids, uid, callback) { privileges.posts.get = function(pids, uid, callback) {
if (pids && pids.length > 50) {
var e = new Error('too many keys')
winston.warn('[TOO_MANY_KEYS] ' + pids.length, e.stack);
}
async.parallel({ async.parallel({
manage_content: function(next) { manage_content: function(next) {
helpers.hasEnoughReputationFor('privileges:manage_content', uid, next); helpers.hasEnoughReputationFor('privileges:manage_content', uid, next);

@ -254,23 +254,22 @@ SocketPosts.getPrivileges = function(socket, pid, callback) {
}); });
}; };
SocketPosts.getFavouritedUsers = function(socket, pid, callback) {
favourites.getFavouritedUidsByPids([pid], function(err, data) {
if (err || !Array.isArray(data) || !data.length) {
return callback(err);
}
user.getUsernamesByUids(data[0], callback);
});
};
SocketPosts.getUpvoters = function(socket, pid, callback) { SocketPosts.getUpvoters = function(socket, pid, callback) {
favourites.getUpvotedUidsByPids([pid], function(err, data) { favourites.getUpvotedUidsByPids([pid], function(err, data) {
if (err || !Array.isArray(data) || !data.length) { if (err || !Array.isArray(data) || !data.length) {
return callback(err, []); return callback(err, []);
} }
var otherCount = 0;
user.getUsernamesByUids(data[0], callback); if (data[0].length > 6) {
otherCount = data[0].length - 5;
data[0] = data[0].slice(0, 5);
}
user.getUsernamesByUids(data[0], function(err, usernames) {
callback(err, {
otherCount: otherCount,
usernames: usernames
});
});
}); });
}; };

@ -244,10 +244,6 @@ var async = require('async'),
}; };
Topics.getTopicWithPosts = function(tid, set, uid, start, end, reverse, callback) { Topics.getTopicWithPosts = function(tid, set, uid, start, end, reverse, callback) {
if (isNaN(start) || isNaN(end)) {
var e = new Error('TOO LARGE');
winston.warn('IS_NAN_CHECK set, start, end, uid, tid', set, start, end, uid, tid, e.stack);
}
Topics.getTopicData(tid, function(err, topicData) { Topics.getTopicData(tid, function(err, topicData) {
if (err || !topicData) { if (err || !topicData) {
return callback(err || new Error('[[error:no-topic]]')); return callback(err || new Error('[[error:no-topic]]'));
@ -268,10 +264,7 @@ var async = require('async'),
if (err) { if (err) {
return next(err); return next(err);
} }
if (posts.length > 100) {
var e = new Error('TOO LARGE');
winston.warn('GET_TOPIC_WITH_POSTS set, start, end, uid, tid', set, start, end, uid, tid, e.stack);
}
Topics.addPostData(posts, uid, next); Topics.addPostData(posts, uid, next);
}); });
}); });

@ -38,10 +38,6 @@ module.exports = function(Topics) {
}; };
Topics.addPostData = function(postData, uid, callback) { Topics.addPostData = function(postData, uid, callback) {
if (postData && postData.length > 50) {
var e = new Error('too many keys');
winston.warn('[ADD POST DATA] ' + postData.length, e.stack);
}
var pids = postData.map(function(post) { var pids = postData.map(function(post) {
return post && post.pid; return post && post.pid;
}); });

@ -135,7 +135,7 @@ var async = require('async'),
return notification ? notification.pid : null; return notification ? notification.pid : null;
}); });
generatePostPaths(pids, uid, function(err, paths) { generatePostPaths(pids, uid, function(err, pidToPaths) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
@ -146,7 +146,7 @@ var async = require('async'),
} }
notification.read = hasRead[index]; notification.read = hasRead[index];
notification.path = paths[index] || notification.path || ''; notification.path = pidToPaths[notification.pid] || notification.path || '';
notification.datetimeISO = utils.toISOString(notification.datetime); notification.datetimeISO = utils.toISOString(notification.datetime);
notification.readClass = !notification.read ? 'label-warning' : ''; notification.readClass = !notification.read ? 'label-warning' : '';
return notification; return notification;
@ -159,7 +159,7 @@ var async = require('async'),
}; };
function generatePostPaths(pids, uid, callback) { function generatePostPaths(pids, uid, callback) {
var postKeys = pids.map(function(pid) { var postKeys = pids.filter(Boolean).map(function(pid) {
return 'post:' + pid; return 'post:' + pid;
}); });
@ -184,18 +184,16 @@ var async = require('async'),
return callback(err); return callback(err);
} }
var paths = []; var pidToPaths = {};
pids.forEach(function(pid, index) { pids.forEach(function(pid, index) {
var slug = results.topics[index] ? results.topics[index].slug : null; var slug = results.topics[index] ? results.topics[index].slug : null;
var postIndex = utils.isNumber(results.indices[index]) ? parseInt(results.indices[index], 10) + 1 : null; var postIndex = utils.isNumber(results.indices[index]) ? parseInt(results.indices[index], 10) + 1 : null;
if (slug && postIndex) { if (slug && postIndex) {
paths.push(nconf.get('relative_path') + '/topic/' + slug + '/' + postIndex); pidToPaths[pid] = nconf.get('relative_path') + '/topic/' + slug + '/' + postIndex;
} else {
paths.push(null);
} }
}); });
callback(null, paths); callback(null, pidToPaths);
}); });
}); });
} }

Loading…
Cancel
Save