From f99c1f9921606aff48312c741bd9b50529a557d6 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Sat, 8 Mar 2014 02:56:24 -0500 Subject: [PATCH 01/10] removed code climate badge until analysis is complete --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index b45429cdf8..90f3dcd600 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # NodeBB [![Dependency Status](https://david-dm.org/designcreateplay/nodebb.png)](https://david-dm.org/designcreateplay/nodebb) -[![Code Climate](https://codeclimate.com/github/designcreateplay/NodeBB.png)](https://codeclimate.com/github/designcreateplay/NodeBB) **NodeBB Forum Software** is powered by Node.js and built on a Redis database. It utilizes web sockets for instant interactions and real-time notifications. NodeBB is compatible down to IE8 and has many modern features out of the box such as social network integration and streaming discussions. From 284276cbb649ce675d91cbee88f8b1212f034c2d Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sat, 8 Mar 2014 15:45:42 -0500 Subject: [PATCH 02/10] messaging jshint --- src/messaging.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/messaging.js b/src/messaging.js index 56a7119a2b..e72ec95d2d 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -1,3 +1,5 @@ +'use strict'; + var db = require('./database'), async = require('async'), user = require('./user'), @@ -35,7 +37,7 @@ var db = require('./database'), Messaging.updateChatTime(touid, fromuid); callback(null, message); }); - } + }; Messaging.getMessages = function(fromuid, touid, callback) { var uids = sortUids(fromuid, touid); From 5a8a3627d24d6ff1a91d3c9be85987f665436923 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sat, 8 Mar 2014 16:04:22 -0500 Subject: [PATCH 03/10] bringing subfolder installations to v0.4.0 - JUST FOR @PLANNER --- public/src/app.js | 3 ++- src/meta.js | 2 +- src/routes/plugins.js | 8 ++++---- src/socket.io/index.js | 4 ++-- src/webserver.js | 11 +++++------ 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index 2eac126888..2308f440b9 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -28,7 +28,8 @@ var socket, var reconnection_delay = 200; socket = io.connect('', { 'max reconnection attempts': max_reconnection_attemps, - 'reconnection delay': reconnection_delay + 'reconnection delay': reconnection_delay, + resource: RELATIVE_PATH.slice(1) + '/socket.io' }); var reconnecting = false, diff --git a/src/meta.js b/src/meta.js index 197351a11d..f8196c9fba 100644 --- a/src/meta.js +++ b/src/meta.js @@ -246,7 +246,7 @@ var fs = require('fs'), 'src/overrides.js', 'src/utils.js' ], - minFile: nconf.get('relative_path') + 'nodebb.min.js', + minFile: 'nodebb.min.js', get: function (callback) { plugins.fireHook('filter:scripts.get', this.scripts, function(err, scripts) { var ctime, diff --git a/src/routes/plugins.js b/src/routes/plugins.js index 00f37d8d02..1d6d9684cb 100644 --- a/src/routes/plugins.js +++ b/src/routes/plugins.js @@ -6,9 +6,10 @@ var nconf = require('nconf'), validator = require('validator'), _ = require('underscore'), async = require('async'), - plugins = require('../plugins'), + plugins = require('../plugins'); - PluginRoutes = function(app) { +(function(Plugins) { + Plugins.createRoutes = function(app) { app.get('/plugins/fireHook', function(req, res) { // GET = filter plugins.fireHook('filter:' + req.query.hook, req.query.args, function(err, returnData) { @@ -70,5 +71,4 @@ var nconf = require('nconf'), } }); }; - -module.exports = PluginRoutes; +})(exports); diff --git a/src/socket.io/index.js b/src/socket.io/index.js index c62fd2f9c6..d477273649 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -28,11 +28,11 @@ var io; Sockets.init = function(server) { - io = socketioWildcard(SocketIO).listen(server, { log: false, transports: ['websocket', 'xhr-polling', 'jsonp-polling', 'flashsocket'], - 'browser client minification': true + 'browser client minification': true, + resource: nconf.get('relative_path') + '/socket.io' }); Sockets.server = io; diff --git a/src/webserver.js b/src/webserver.js index e6013d0752..6c658974db 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -33,7 +33,8 @@ var path = require('path'), userRoute = require('./routes/user'), apiRoute = require('./routes/api'), feedsRoute = require('./routes/feeds'), - metaRoute = require('./routes/meta'); + metaRoute = require('./routes/meta'), + pluginsRoute = require('./routes/plugins'); if(nconf.get('ssl')) { server = require('https').createServer({ @@ -312,7 +313,7 @@ process.on('uncaughtException', function(err) { // Theme's static directory if (themeData['theme:staticDir']) { - app.use('/css/assets', express.static(path.join(nconf.get('themes_path'), themeData['theme:id'], themeData['theme:staticDir']), { + app.use(nconf.get('relative_path') + '/css/assets', express.static(path.join(nconf.get('themes_path'), themeData['theme:id'], themeData['theme:staticDir']), { maxAge: app.enabled('cache') ? 5184000000 : 0 })); if (process.env.NODE_ENV === 'development') { @@ -321,7 +322,7 @@ process.on('uncaughtException', function(err) { } if (themeData['theme:templates']) { - app.use('/templates', express.static(path.join(nconf.get('themes_path'), themeData['theme:id'], themeData['theme:templates']), { + app.use(nconf.get('relative_path') + '/templates', express.static(path.join(nconf.get('themes_path'), themeData['theme:id'], themeData['theme:templates']), { maxAge: app.enabled('cache') ? 5184000000 : 0 })); if (process.env.NODE_ENV === 'development') { @@ -493,6 +494,7 @@ process.on('uncaughtException', function(err) { userRoute.createRoutes(app); apiRoute.createRoutes(app); feedsRoute.createRoutes(app); + pluginsRoute.createRoutes(app); // Basic Routes (entirely client-side parsed, goal is to move the rest of the crap in this file into this one section) (function () { @@ -939,9 +941,6 @@ process.on('uncaughtException', function(err) { }); }); - // Other routes - require('./routes/plugins')(app); - // Debug routes if (process.env.NODE_ENV === 'development') { require('./routes/debug')(app); From f00f7c881853ae19a09e8b941e049173ee1e60d5 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sat, 8 Mar 2014 16:08:52 -0500 Subject: [PATCH 04/10] fixed apple-touch-icon for subfolder installs --- src/webserver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webserver.js b/src/webserver.js index 6c658974db..d7d7158684 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -248,7 +248,7 @@ process.on('uncaughtException', function(err) { if (meta.config['brand:logo'] && validator.isURL(meta.config['brand:logo'])) { return res.redirect(meta.config['brand:logo']); } else { - return res.sendfile(path.join(__dirname, '../public', meta.config['brand:logo'] || nconf.get('relative_path') + '/logo.png'), { + return res.sendfile(path.join(__dirname, '../public', meta.config['brand:logo'] || '/logo.png'), { maxAge: app.enabled('cache') ? 5184000000 : 0 }); } From 6fb393de780a173eeb35ee73f499b376c0d67b9b Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sat, 8 Mar 2014 16:50:32 -0500 Subject: [PATCH 05/10] fixing #1177 --- public/src/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/src/app.js b/public/src/app.js index 2308f440b9..90f6e63743 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -29,7 +29,7 @@ var socket, socket = io.connect('', { 'max reconnection attempts': max_reconnection_attemps, 'reconnection delay': reconnection_delay, - resource: RELATIVE_PATH.slice(1) + '/socket.io' + resource: RELATIVE_PATH.length ? RELATIVE_PATH.slice(1) + '/socket.io' : 'socket.io' }); var reconnecting = false, From 23e1cc010c27b7f25c5ae56e1cac0dddfc56fabb Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sat, 8 Mar 2014 17:41:23 -0500 Subject: [PATCH 06/10] removed removeHiddenFields function, using mongo selector instead --- src/database/mongo.js | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index a9cc09c2d4..78b3914cc2 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -82,18 +82,6 @@ // // helper functions // - function removeHiddenFields(item) { - if(item) { - if(item._id) { - delete item._id; - } - if(item._key) { - delete item._key; - } - } - return item; - } - function findItem(data, key) { if(!data) { return null; @@ -261,11 +249,7 @@ }; module.getObject = function(key, callback) { - db.collection('objects').findOne({_key:key}, function(err, item) { - removeHiddenFields(item); - - callback(err, item); - }); + db.collection('objects').findOne({_key:key}, {_id:0, _key:0}, callback); }; module.getObjects = function(keys, callback) { @@ -302,7 +286,9 @@ module.getObjectFields = function(key, fields, callback) { - var _fields = {}; + var _fields = { + _id: 0 + }; for(var i=0; i Date: Sun, 9 Mar 2014 00:16:05 -0500 Subject: [PATCH 07/10] optimized getTopicsByTids, single db call to get topicData, added cache for privilege/category/user data --- public/templates/category.tpl | 4 +- public/templates/popular.tpl | 4 +- public/templates/recent.tpl | 4 +- public/templates/unread.tpl | 4 +- src/topics.js | 129 +++++++++++++++++++++------------- 5 files changed, 88 insertions(+), 57 deletions(-) diff --git a/public/templates/category.tpl b/public/templates/category.tpl index f1b6a9c365..03a40c51b7 100644 --- a/public/templates/category.tpl +++ b/public/templates/category.tpl @@ -48,8 +48,8 @@ todo: fix this nesting if issue#1065 is a win todo: add a check for config.allowTopicsThumbnail if issue#1066 is a win --> - - + +

diff --git a/public/templates/popular.tpl b/public/templates/popular.tpl index 2ead0b6b08..912d2ea6e7 100644 --- a/public/templates/popular.tpl +++ b/public/templates/popular.tpl @@ -26,8 +26,8 @@
  • - - + +

    diff --git a/public/templates/recent.tpl b/public/templates/recent.tpl index 31765697be..a3b9ebde6b 100644 --- a/public/templates/recent.tpl +++ b/public/templates/recent.tpl @@ -27,8 +27,8 @@
  • - - + +

    diff --git a/public/templates/unread.tpl b/public/templates/unread.tpl index 58cd9eab1e..201cf76f14 100644 --- a/public/templates/unread.tpl +++ b/public/templates/unread.tpl @@ -21,8 +21,8 @@
  • - - + +

    diff --git a/src/topics.js b/src/topics.js index 7be77d3458..dcdfe05298 100644 --- a/src/topics.js +++ b/src/topics.js @@ -323,17 +323,35 @@ var async = require('async'), }; Topics.getTopicData = function(tid, callback) { - db.getObject('topic:' + tid, function(err, data) { - if(err) { - return callback(err, null); + Topics.getTopicsData([tid], function(err, topics) { + if (err) { + return callback(err); } - if(data) { - data.title = validator.escape(data.title); - data.relativeTime = utils.toISOString(data.timestamp); + callback(null, topics ? topics[0] : null); + }); + }; + + Topics.getTopicsData = function(tids, callback) { + var keys = []; + + for (var i=0; i Date: Sun, 9 Mar 2014 00:20:29 -0500 Subject: [PATCH 08/10] return user object --- src/topics.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/topics.js b/src/topics.js index dcdfe05298..b40201e69a 100644 --- a/src/topics.js +++ b/src/topics.js @@ -370,9 +370,12 @@ var async = require('async'), userData = {}; } - topic.username = userData.username || 'Anonymous'; - topic.userslug = userData.userslug || ''; - topic.picture = userData.picture || gravatar.url('', {}, true); + topic.user = { + username: userData.username || 'Anonymous', + userslug: userData.userslug || '', + picture: userData.picture || gravatar.url('', {}, true) + }; + callback(null, topic); }); }); @@ -709,7 +712,7 @@ var async = require('async'), }, privileges: function(next) { if (privilegeCache[topicData.cid]) { - return next(null, privilegeCache[topicData.cid]) + return next(null, privilegeCache[topicData.cid]); } categoryTools.privileges(topicData.cid, uid, next); }, From 820cdf8a47b09f6e21459c031cb9b9f660535d72 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 9 Mar 2014 00:47:21 -0500 Subject: [PATCH 09/10] temporarily removing cronjob until upstream bugs are fixed -- resolved #1178 --- app.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index ec15115694..c38b06e262 100644 --- a/app.js +++ b/app.js @@ -148,7 +148,8 @@ function start() { templates.ready(webserver.init); }); - notifications.init(); + // Temporarily removed until ncb000gt/node-cron/issues/81 and ncb000gt/node-cron/issues/83 are fixed + // notifications.init(); } else { winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:'); winston.warn(' node app --upgrade'); From 6496b91c29378edea7f969988880b23722c7cf24 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 9 Mar 2014 14:02:30 -0400 Subject: [PATCH 10/10] closes #1180 --- public/src/forum/footer.js | 6 ++---- src/socket.io/topics.js | 2 +- src/socket.io/user.js | 2 +- src/topics.js | 10 +++++----- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js index e866b70cf9..f93277a4b5 100644 --- a/public/src/forum/footer.js +++ b/public/src/forum/footer.js @@ -8,13 +8,11 @@ define(['notifications', 'chat'], function(Notifications, Chat) { Chat.prepareDOM(); translator.prepareDOM(); - function updateUnreadCount(err, tids) { - var count = 0, unreadEl = $('#unread-count'); + function updateUnreadCount(err, count) { + var unreadEl = $('#unread-count'); if (err) { console.warn('Error updating unread count', err); - } else if(tids && tids.length) { - count = tids.length; } unreadEl diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js index 80139d2f65..5a82e39402 100644 --- a/src/socket.io/topics.js +++ b/src/socket.io/topics.js @@ -101,7 +101,7 @@ SocketTopics.markAllRead = function(socket, data, callback) { return callback(err); } - index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', null, []); + index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', null, 0); callback(); }); diff --git a/src/socket.io/user.js b/src/socket.io/user.js index 05fa97fcb0..f62e95ccfd 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -214,7 +214,7 @@ SocketUser.getOnlineAnonCount = function(socket, data, callback) { }; SocketUser.getUnreadCount = function(socket, data, callback) { - topics.getUnreadTids(socket.uid, 0, 19, callback); + topics.getTotalUnread(socket.uid, callback); }; SocketUser.getActiveUsers = function(socket, data, callback) { diff --git a/src/topics.js b/src/topics.js index b40201e69a..f4c12f4414 100644 --- a/src/topics.js +++ b/src/topics.js @@ -559,8 +559,8 @@ var async = require('async'), }; Topics.getTotalUnread = function(uid, callback) { - Topics.getUnreadTids(uid, 0, 21, function(err, tids) { - callback(err, {count: tids ? tids.length : 0}); + Topics.getUnreadTids(uid, 0, 20, function(err, tids) { + callback(err, tids ? tids.length : 0); }); }; @@ -574,7 +574,7 @@ var async = require('async'), } async.whilst(function() { - return unreadTids.length < 20 && !done; + return unreadTids.length < 21 && !done; }, function(callback) { Topics.getLatestTids(start, stop, 'month', function(err, tids) { if (err) { @@ -671,8 +671,8 @@ var async = require('async'), }); async.each(uids, function(uid, next) { - Topics.getUnreadTids(uid, 0, 19, function(err, tids) { - websockets.in('uid_' + uid).emit('event:unread.updateCount', null, tids); + Topics.getTotalUnread(uid, function(err, count) { + websockets.in('uid_' + uid).emit('event:unread.updateCount', null, count); next(); }); }, function(err) {