From 57e204df8e1f6cee59fd5af5ed437378d0528431 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sat, 6 Sep 2014 20:46:18 -0400 Subject: [PATCH] removed most of the debug dont get more than 6 usernames for upvote tooltips generatePostPaths wont check null pids --- public/src/forum/topic/postTools.js | 22 +++++++--------------- src/posts.js | 7 +++---- src/privileges/posts.js | 4 ---- src/socket.io/posts.js | 23 +++++++++++------------ src/topics.js | 9 +-------- src/topics/posts.js | 4 ---- src/user/notifications.js | 14 ++++++-------- 7 files changed, 28 insertions(+), 55 deletions(-) diff --git a/public/src/forum/topic/postTools.js b/public/src/forum/topic/postTools.js index 3b63650942..2bc22cb06a 100644 --- a/public/src/forum/topic/postTools.js +++ b/public/src/forum/topic/postTools.js @@ -14,8 +14,6 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com share.addShareHandlers(topicName); - addFavouriteHandler(); - 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() { $('#post-container').on('mouseenter', '.post-row .votes', function() { loadDataAndCreateTooltip($(this), 'posts.getUpvoters'); @@ -51,21 +43,21 @@ define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(com function loadDataAndCreateTooltip(el, method) { 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) { - createTooltip(el, usernames); + createTooltip(el, data); } }); } - function createTooltip(el, usernames) { + function createTooltip(el, data) { + var usernames = data.usernames; if (!usernames.length) { return; } - if (usernames.length > 6) { - var otherCount = usernames.length - 5; - usernames = usernames.slice(0, 5).join(', ').replace(/,/g, '|'); - translator.translate('[[topic:users_and_others, ' + usernames + ', ' + otherCount + ']]', function(translated) { + if (usernames.length + data.otherCount > 6) { + usernames = usernames.join(', ').replace(/,/g, '|'); + translator.translate('[[topic:users_and_others, ' + usernames + ', ' + data.otherCount + ']]', function(translated) { translated = translated.replace(/\|/g, ','); el.attr('title', translated).tooltip('destroy').tooltip('show'); }); diff --git a/src/posts.js b/src/posts.js index 1327b41060..2a895d329a 100644 --- a/src/posts.js +++ b/src/posts.js @@ -109,14 +109,13 @@ var async = require('async'), }; Posts.getPidsFromSet = function(set, start, end, reverse, callback) { + if (isNaN(start) || isNaN(end)) { + return callback(null, []); + } db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, end, 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 = []; for(var x=0, numPids=pids.length; x 50) { - var e = new Error('too many keys') - winston.warn('[TOO_MANY_KEYS] ' + pids.length, e.stack); - } async.parallel({ manage_content: function(next) { helpers.hasEnoughReputationFor('privileges:manage_content', uid, next); diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index 2fa2ff1bf3..e85114f592 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -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) { favourites.getUpvotedUidsByPids([pid], function(err, data) { if (err || !Array.isArray(data) || !data.length) { return callback(err, []); } - - user.getUsernamesByUids(data[0], callback); + var otherCount = 0; + 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 + }); + }); }); }; diff --git a/src/topics.js b/src/topics.js index a828047cfc..d43cb0fb31 100644 --- a/src/topics.js +++ b/src/topics.js @@ -244,10 +244,6 @@ var async = require('async'), }; 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) { if (err || !topicData) { return callback(err || new Error('[[error:no-topic]]')); @@ -268,10 +264,7 @@ var async = require('async'), if (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); }); }); diff --git a/src/topics/posts.js b/src/topics/posts.js index 20edb89ea4..a8e4eacc79 100644 --- a/src/topics/posts.js +++ b/src/topics/posts.js @@ -38,10 +38,6 @@ module.exports = function(Topics) { }; 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) { return post && post.pid; }); diff --git a/src/user/notifications.js b/src/user/notifications.js index c50b854560..e165512178 100644 --- a/src/user/notifications.js +++ b/src/user/notifications.js @@ -135,7 +135,7 @@ var async = require('async'), return notification ? notification.pid : null; }); - generatePostPaths(pids, uid, function(err, paths) { + generatePostPaths(pids, uid, function(err, pidToPaths) { if (err) { return callback(err); } @@ -146,7 +146,7 @@ var async = require('async'), } notification.read = hasRead[index]; - notification.path = paths[index] || notification.path || ''; + notification.path = pidToPaths[notification.pid] || notification.path || ''; notification.datetimeISO = utils.toISOString(notification.datetime); notification.readClass = !notification.read ? 'label-warning' : ''; return notification; @@ -159,7 +159,7 @@ var async = require('async'), }; function generatePostPaths(pids, uid, callback) { - var postKeys = pids.map(function(pid) { + var postKeys = pids.filter(Boolean).map(function(pid) { return 'post:' + pid; }); @@ -184,18 +184,16 @@ var async = require('async'), return callback(err); } - var paths = []; + var pidToPaths = {}; pids.forEach(function(pid, index) { var slug = results.topics[index] ? results.topics[index].slug : null; var postIndex = utils.isNumber(results.indices[index]) ? parseInt(results.indices[index], 10) + 1 : null; if (slug && postIndex) { - paths.push(nconf.get('relative_path') + '/topic/' + slug + '/' + postIndex); - } else { - paths.push(null); + pidToPaths[pid] = nconf.get('relative_path') + '/topic/' + slug + '/' + postIndex; } }); - callback(null, paths); + callback(null, pidToPaths); }); }); }