From f9fecf4bc1a18f576a3bd29742c75cead662a603 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 28 Jan 2015 19:19:55 -0500 Subject: [PATCH 1/4] faster sort users --- src/user/search.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/user/search.js b/src/user/search.js index bad43be25b..95130bf68f 100644 --- a/src/user/search.js +++ b/src/user/search.js @@ -178,18 +178,20 @@ module.exports = function(User) { } function sortUsers(userData, sortBy) { - userData.sort(function(user1, user2) { - if (sortBy === 'joindate' || sortBy === 'postcount') { - return user2[sortBy] - user1[sortBy]; - } else { - if(user1[sortBy] < user2[sortBy]) { + if (sortBy === 'joindate' || sortBy === 'postcount') { + userData.sort(function(u1, u2) { + return u2[sortBy] - u1[sortBy]; + }); + } else { + userData.sort(function(u1, u2) { + if(u1[sortBy] < u2[sortBy]) { return -1; - } else if(user1[sortBy] > user2[sortBy]) { + } else if(u1[sortBy] > u2[sortBy]) { return 1; } return 0; - } - }); + }); + } } function searchByIP(ip, callback) { From 4d6a6f64b0e2dd1b4c15a2e24caa213618a76b13 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 28 Jan 2015 23:43:08 -0500 Subject: [PATCH 2/4] slug is lowercase --- tests/user.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/user.js b/tests/user.js index 381c6f0a44..466379c6e8 100644 --- a/tests/user.js +++ b/tests/user.js @@ -174,7 +174,7 @@ describe('User', function() { describe('.delete()', function() { var uid; before(function(done) { - User.create({username: 'userToDelete', password: '123456', email: 'delete@me.com'}, function(err, newUid) { + User.create({username: 'usertodelete', password: '123456', email: 'delete@me.com'}, function(err, newUid) { assert.ifError(err); uid = newUid; done(); @@ -184,7 +184,7 @@ describe('User', function() { it('should delete a user account', function(done) { User.delete(uid, function(err) { assert.ifError(err); - User.exists('userToDelete', function(err, exists) { + User.exists('usertodelete', function(err, exists) { assert.ifError(err); assert.equal(exists, false); done(); From aaa1fae55828e8451ec1ca818504c3776611b340 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 29 Jan 2015 01:06:48 -0500 Subject: [PATCH 3/4] closes #2597 --- public/src/client/topic/posts.js | 2 -- src/controllers/categories.js | 11 ++++++++--- src/controllers/helpers.js | 34 ++++++++++++++++++++++++-------- src/controllers/index.js | 20 +++++++++++++++---- src/controllers/search.js | 6 ++++-- src/controllers/tags.js | 20 ++++++++++++++----- src/controllers/topics.js | 3 ++- 7 files changed, 71 insertions(+), 25 deletions(-) diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.js index 8e21928498..ec566d9812 100644 --- a/public/src/client/topic/posts.js +++ b/public/src/client/topic/posts.js @@ -34,8 +34,6 @@ define('forum/topic/posts', [ var posts = data.posts; socket.emit('topics.getPageCount', ajaxify.variables.get('topic_id'), function(err, newPageCount) { - pagination.recreatePaginationLinks(newPageCount); - if (pagination.currentPage === pagination.pageCount) { createNewPosts(data); } else if(data.posts && data.posts.length && parseInt(data.posts[0].uid, 10) === parseInt(app.uid, 10)) { diff --git a/src/controllers/categories.js b/src/controllers/categories.js index 5083a7d71a..1783fd69b3 100644 --- a/src/controllers/categories.js +++ b/src/controllers/categories.js @@ -22,7 +22,8 @@ categoriesController.recent = function(req, res, next) { } data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1; - + data['rssFeedUrl'] = nconf.get('relative_path') + '/recent.rss'; + data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[recent:title]]'}]); res.render('recent', data); }); }; @@ -52,7 +53,9 @@ categoriesController.popular = function(req, res, next) { var data = { topics: topics, - 'feeds:disableRSS': parseInt(meta.config['feeds:disableRSS'], 10) === 1 + 'feeds:disableRSS': parseInt(meta.config['feeds:disableRSS'], 10) === 1, + rssFeedUrl: nconf.get('relative_path') + '/popular.rss', + breadcrumbs: helpers.buildBreadcrumbs([{text: '[[global:header.popular]]'}]) }; if (uid === 0) { @@ -72,6 +75,7 @@ categoriesController.unread = function(req, res, next) { return next(err); } + data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[unread:title]]'}]); res.render('unread', data); }); }; @@ -188,7 +192,7 @@ categoriesController.get = function(req, res, next) { url: nconf.get('relative_path') + '/category/' + categoryData.slug } ]; - helpers.buildBreadcrumbs(categoryData.parentCid, function(err, crumbs) { + helpers.buildCategoryBreadcrumbs(categoryData.parentCid, function(err, crumbs) { if (err) { return next(err); } @@ -255,6 +259,7 @@ categoriesController.get = function(req, res, next) { data.currentPage = page; data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1; + data['rssFeedUrl'] = nconf.get('relative_path') + '/category/' + data.cid + '.rss'; pagination.create(data.currentPage, data.pageCount, data); diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js index 45d6ea7579..7958ace2df 100644 --- a/src/controllers/helpers.js +++ b/src/controllers/helpers.js @@ -38,7 +38,7 @@ helpers.notAllowed = function(req, res, error) { } }; -helpers.buildBreadcrumbs = function(cid, callback) { +helpers.buildCategoryBreadcrumbs = function(cid, callback) { var breadcrumbs = []; async.whilst(function() { @@ -62,15 +62,33 @@ helpers.buildBreadcrumbs = function(cid, callback) { return callback(err); } - translator.translate('[[global:home]]', meta.config.defaultLang || 'en_GB', function(translated) { - breadcrumbs.unshift({ - text: translated, - url: nconf.get('relative_path') + '/' - }); - - callback(null, breadcrumbs); + breadcrumbs.unshift({ + text: '[[global:home]]', + url: nconf.get('relative_path') + '/' }); + + callback(null, breadcrumbs); + }); +}; + +helpers.buildBreadcrumbs = function(crumbs) { + var breadcrumbs = [ + { + text: '[[global:home]]', + url: nconf.get('relative_path') + '/' + } + ]; + + crumbs.forEach(function(crumb) { + if (crumb) { + if (crumb.url) { + crumb.url = nconf.get('relative_path') + crumb.url; + } + breadcrumbs.push(crumb); + } }); + + return breadcrumbs; }; module.exports = helpers; \ No newline at end of file diff --git a/src/controllers/index.js b/src/controllers/index.js index 49bf28f35c..797d30e22d 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -105,9 +105,18 @@ Controllers.home = function(req, res, next) { }; Controllers.reset = function(req, res, next) { - res.render(req.params.code ? 'reset_code' : 'reset', { - reset_code: req.params.code ? req.params.code : null - }); + if (req.params.code) { + res.render('reset_code', { + reset_code: req.params.code ? req.params.code : null, + breadcrumbs: helpers.buildBreadcrumbs([{text: '[[reset_password:reset_password]]', url: '/reset'}, {text: '[[reset_password:update_password]]'}]) + }); + } else { + res.render('reset', { + reset_code: req.params.code ? req.params.code : null, + breadcrumbs: helpers.buildBreadcrumbs([{text: '[[reset_password:reset_password]]'}]) + }); + } + }; Controllers.login = function(req, res, next) { @@ -120,6 +129,7 @@ Controllers.login = function(req, res, next) { data.showResetLink = emailersPresent; data.allowLocalLogin = parseInt(meta.config.allowLocalLogin, 10) === 1; data.allowRegistration = parseInt(meta.config.allowRegistration, 10) === 1; + data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:login]]'}]); data.error = req.flash('error')[0]; res.render('login', data); @@ -151,6 +161,7 @@ Controllers.register = function(req, res, next) { data.maximumUsernameLength = meta.config.maximumUsernameLength; data.minimumPasswordLength = meta.config.minimumPasswordLength; data.termsOfUse = meta.config.termsOfUse; + data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[register:register]]'}]); data.regFormEntry = []; data.error = req.flash('error')[0]; @@ -200,7 +211,8 @@ Controllers.outgoing = function(req, res, next) { var url = req.query.url, data = { url: url, - title: meta.config.title + title: meta.config.title, + breadcrumbs: helpers.buildBreadcrumbs([{text: '[[notifications:outgoing_link]]'}]) }; if (url) { diff --git a/src/controllers/search.js b/src/controllers/search.js index 1a5690a6e7..355fddeced 100644 --- a/src/controllers/search.js +++ b/src/controllers/search.js @@ -12,7 +12,7 @@ searchController.search = function(req, res, next) { if (!plugins.hasListeners('filter:search.query')) { return helpers.notFound(req, res); } - + var breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:search]]'}]); if (!req.params.term) { return res.render('search', { time: 0, @@ -20,7 +20,8 @@ searchController.search = function(req, res, next) { posts: [], topics: [], users: [], - tags: [] + tags: [], + breadcrumbs: breadcrumbs }); } @@ -38,6 +39,7 @@ searchController.search = function(req, res, next) { return next(err); } + results.breadcrumbs = breadcrumbs; res.render('search', results); }); }; diff --git a/src/controllers/tags.js b/src/controllers/tags.js index 269e5a3599..3d450e06a7 100644 --- a/src/controllers/tags.js +++ b/src/controllers/tags.js @@ -5,7 +5,8 @@ var tagsController = {}, nconf = require('nconf'), validator = require('validator'), meta = require('../meta'), - topics = require('../topics'); + topics = require('../topics'), + helpers = require('./helpers'); tagsController.getTag = function(req, res, next) { var tag = validator.escape(req.params.tag); @@ -41,8 +42,13 @@ tagsController.getTag = function(req, res, next) { content: nconf.get('url') + '/tags/' + tag } ]; - - res.render('tag', {topics: topics, tag: tag, nextStart: end + 1}); + var data = { + topics: topics, + tag: tag, + nextStart: end + 1, + breadcrumbs: helpers.buildBreadcrumbs([{text: '[[tags:tags]]', url: '/tags'}, {text: tag}]) + }; + res.render('tag', data); }); }); }; @@ -52,8 +58,12 @@ tagsController.getTags = function(req, res, next) { if (err) { return next(err); } - - res.render('tags', {tags: tags, nextStart: 100}); + var data = { + tags: tags, + nextStart: 100, + breadcrumbs: helpers.buildBreadcrumbs([{text: '[[tags:tags]]'}]) + }; + res.render('tags', data); }); }; diff --git a/src/controllers/topics.js b/src/controllers/topics.js index d3d6e571e6..6b3b42ab93 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -139,7 +139,7 @@ topicsController.get = function(req, res, next) { } ]; - helpers.buildBreadcrumbs(topicData.category.parentCid, function(err, crumbs) { + helpers.buildCategoryBreadcrumbs(topicData.category.parentCid, function(err, crumbs) { if (err) { return next(err); } @@ -255,6 +255,7 @@ topicsController.get = function(req, res, next) { data['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1; data['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1; data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1; + data['rssFeedUrl'] = nconf.get('relative_path') + '/topic/' + data.tid + '.rss'; topics.increaseViewCount(tid); From a1c8902b4eee68b2d819f31ffeeec215873747ce Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 29 Jan 2015 12:52:30 -0500 Subject: [PATCH 4/4] hook fixes new hook, action:user.online, fix action:user.set hooks so they pass in uid check err before firing hooks --- src/user.js | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/user.js b/src/user.js index 998ce2db23..ccb30fecfb 100644 --- a/src/user.js +++ b/src/user.js @@ -152,23 +152,37 @@ var async = require('async'), if (err || now - parseInt(score, 10) < 300000) { return callback(err); } - db.sortedSetAdd('users:online', now, uid, callback); + db.sortedSetAdd('users:online', now, uid, function(err) { + if (err) { + return callback(err); + } + plugins.fireHook('action:user.online', {uid: uid, timestamp: now}); + }); }); }; User.setUserField = function(uid, field, value, callback) { - plugins.fireHook('action:user.set', {field: field, value: value, type: 'set'}); - db.setObjectField('user:' + uid, field, value, callback); + db.setObjectField('user:' + uid, field, value, function(err) { + if (err) { + return callback(err) + } + plugins.fireHook('action:user.set', {uid: uid, field: field, value: value, type: 'set'}); + callback(); + }); }; User.setUserFields = function(uid, data, callback) { - for (var field in data) { - if (data.hasOwnProperty(field)) { - plugins.fireHook('action:user.set', {field: field, value: data[field], type: 'set'}); + db.setObject('user:' + uid, data, function(err) { + if (err) { + return callback(err); } - } - - db.setObject('user:' + uid, data, callback); + for (var field in data) { + if (data.hasOwnProperty(field)) { + plugins.fireHook('action:user.set', {uid: uid, field: field, value: data[field], type: 'set'}); + } + } + callback(); + }); }; User.incrementUserFieldBy = function(uid, field, value, callback) { @@ -177,7 +191,7 @@ var async = require('async'), if (err) { return callback(err); } - plugins.fireHook('action:user.set', {field: field, value: value, type: 'increment'}); + plugins.fireHook('action:user.set', {uid: uid, field: field, value: value, type: 'increment'}); callback(null, value); }); @@ -189,7 +203,7 @@ var async = require('async'), if (err) { return callback(err); } - plugins.fireHook('action:user.set', {field: field, value: value, type: 'decrement'}); + plugins.fireHook('action:user.set', {uid: uid, field: field, value: value, type: 'decrement'}); callback(null, value); });