From d3ba03ceaec5a0ab543b946eea98f7e70ed451bc Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 21 Feb 2014 11:16:44 -0500 Subject: [PATCH 1/5] fixed #1089 --- src/user.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/user.js b/src/user.js index 1a048c9d73..39f0befef9 100644 --- a/src/user.js +++ b/src/user.js @@ -1136,8 +1136,9 @@ var bcrypt = require('bcryptjs'), async.filter(nids, function(nid, next) { notifications.get(nid, uid, function(notifObj) { if(!notifObj) { - next(false); + return next(false); } + if (notifObj.uniqueId === uniqueId) { next(true); } else { From f6ea278b09fb56e304779e895d2967ef06a90109 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 21 Feb 2014 13:27:40 -0500 Subject: [PATCH 2/5] closed #1095 --- src/meta.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/meta.js b/src/meta.js index d95614b082..fd344b460e 100644 --- a/src/meta.js +++ b/src/meta.js @@ -243,7 +243,7 @@ var fs = require('fs'), minFile: path.join(__dirname, '..', 'public/src/nodebb.min.js'), get: function (callback) { plugins.fireHook('filter:scripts.get', this.scripts, function(err, scripts) { - var mtime, + var ctime, jsPaths = scripts.map(function (jsPath) { jsPath = path.normalize(jsPath); @@ -267,12 +267,12 @@ var fs = require('fs'), if (process.env.NODE_ENV !== 'development') { async.parallel({ - mtime: function (next) { + ctime: function (next) { async.map(jsPaths, fs.stat, function (err, stats) { async.reduce(stats, 0, function (memo, item, next) { if(item) { - mtime = +new Date(item.mtime); - next(null, mtime > memo ? mtime : memo); + ctime = +new Date(item.ctime); + next(null, ctime > memo ? ctime : memo); } else { next(null, memo); } @@ -286,14 +286,15 @@ var fs = require('fs'), } fs.stat(Meta.js.minFile, function (err, stat) { - next(err, +new Date(stat.mtime)); + next(err, +new Date(stat.ctime)); }); } }, function (err, results) { - if (results.minFile > results.mtime) { + if (results.minFile > results.ctime) { winston.info('No changes to client-side libraries -- skipping minification'); callback(null, [path.relative(path.join(__dirname, '../public'), Meta.js.minFile)]); } else { + winston.info('Minifying client-side libraries -- please wait'); Meta.js.minify(function () { callback(null, [ path.relative(path.join(__dirname, '../public'), Meta.js.minFile) From ea826ce48796be5024f2c630823c3fec01f8e6a0 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 21 Feb 2014 13:55:04 -0500 Subject: [PATCH 3/5] type checking 'plugin' when loading --- src/plugins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins.js b/src/plugins.js index 9614777524..91a51d65c4 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -71,7 +71,7 @@ var fs = require('fs'), plugins.push(meta.config['theme:id']); async.each(plugins, function(plugin, next) { - if (!plugin) { + if (!plugin || typeof plugin !== 'string') { return next(); } From ae93c372fffdb371f7a7eacd5d0aebc3b3ce6d12 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 21 Feb 2014 14:53:31 -0500 Subject: [PATCH 4/5] fixed mongo setAdd and setRemove to accept arrays like redis, fixed infinite scroll for mongo --- src/database/mongo.js | 62 ++++++++++++++++++++++++++++++++----------- src/plugins.js | 3 ++- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index e3a5d3529c..6bd0b5037e 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -20,6 +20,7 @@ module.init = function(callback) { + mongoClient.connect('mongodb://'+ nconf.get('mongo:host') + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'), function(err, _db) { if(err) { winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message); @@ -424,10 +425,23 @@ // sets module.setAdd = function(key, value, callback) { - if(value !== null && value !== undefined) { - value = value.toString(); + if(!Array.isArray(value)) { + value = [value]; } - db.collection('objects').update({_key:key}, {$addToSet: { members: value }}, {upsert:true, w: 1}, function(err, result) { + + value.forEach(function(element, index, array) { + array[index] = element ? element.toString() : element; + }); + + + db.collection('objects').update({_key:key}, + { + $addToSet: { members: { $each: value } } + }, + { + upsert:true, w: 1 + } + , function(err, result) { if(typeof callback === 'function') { callback(err, result); } @@ -435,10 +449,15 @@ } module.setRemove = function(key, value, callback) { - if(value !== null && value !== undefined) { - value = value.toString(); + if(!Array.isArray(value)) { + value = [value]; } - db.collection('objects').update({_key:key, members: value}, {$pull : {members: value}}, function(err, result) { + + value.forEach(function(element, index, array) { + array[index] = element ? element.toString() : element; + }); + + db.collection('objects').update( { _key: key }, { $pullAll: { members: value } }, function(err, result) { if(typeof callback === 'function') { callback(err, result); } @@ -456,17 +475,26 @@ } module.isMemberOfSets = function(sets, value, callback) { - function iterator(set, next) { - module.isSetMember(set, value, function(err, result) { - if(err) { - return next(err); - } - next(null, result?1:0); - }); + if(value !== null && value !== undefined) { + value = value.toString(); } - async.map(sets, iterator, callback); + db.collection('objects').find({_key: {$in : sets}, members: value}).toArray(function(err, result) { + if(err) { + return callback(err); + } + + result = result.map(function(item) { + return item._key; + }); + + result = sets.map(function(set) { + return result.indexOf(set) !== -1 ? 1 : 0; + }); + + callback(err, result); + }); } module.getSetMembers = function(key, callback) { @@ -655,16 +683,18 @@ if(value !== null && value !== undefined) { value = value.toString(); } - module.getSortedSetRange(key, 0, -1, function(err, result) { + module.getSortedSetRevRange(key, 0, -1, function(err, result) { if(err) { return callback(err); } + var rank = result.indexOf(value); + if(rank === -1) { return callback(null, null); } - callback(null, result.length - rank - 1); + callback(null, rank); }); } diff --git a/src/plugins.js b/src/plugins.js index 9614777524..1d0d17535b 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -71,6 +71,7 @@ var fs = require('fs'), plugins.push(meta.config['theme:id']); async.each(plugins, function(plugin, next) { + if (!plugin) { return next(); } @@ -377,7 +378,7 @@ var fs = require('fs'), }).filter(function(file) { var stats = fs.statSync(file), isPlugin = file.substr(npmPluginPath.length + 1, 14) === 'nodebb-plugin-' || file.substr(npmPluginPath.length + 1, 14) === 'nodebb-widget-'; - + if (stats.isDirectory() && isPlugin) return true; else return false; }); From eb3b240b047515ce2b26d3ebad8b8aa149e441ab Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 21 Feb 2014 15:54:51 -0500 Subject: [PATCH 5/5] some cleanup of unread --- src/categories.js | 10 +++++++--- src/database/mongo.js | 1 - src/topics.js | 44 +++++++++++++++---------------------------- 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/categories.js b/src/categories.js index 0e47e7b1a8..2049b22c99 100644 --- a/src/categories.js +++ b/src/categories.js @@ -171,8 +171,14 @@ var db = require('./database'), Categories.isTopicsRead = function(cid, uid, callback) { db.getSortedSetRange('categories:' + cid + ':tid', 0, -1, function(err, tids) { + if(err) { + return callback(err); + } - topics.hasReadTopics(tids, uid, function(hasRead) { + topics.hasReadTopics(tids, uid, function(err, hasRead) { + if(err) { + return callback(err); + } var allread = true; for (var i = 0, ii = tids.length; i < ii; i++) { @@ -271,8 +277,6 @@ var db = require('./database'), }); }; - - Categories.getCategoryData = function(cid, callback) { db.exists('category:' + cid, function(err, exists) { if (exists) { diff --git a/src/database/mongo.js b/src/database/mongo.js index 6bd0b5037e..63338856f6 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -20,7 +20,6 @@ module.init = function(callback) { - mongoClient.connect('mongodb://'+ nconf.get('mongo:host') + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'), function(err, _db) { if(err) { winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message); diff --git a/src/topics.js b/src/topics.js index bdcd055526..6ad23bee70 100644 --- a/src/topics.js +++ b/src/topics.js @@ -518,8 +518,10 @@ var async = require('async'), return callback(null); } - Topics.hasReadTopics(tids, uid, function(read) { - + Topics.hasReadTopics(tids, uid, function(err, read) { + if(err) { + return callback(err); + } var newtids = tids.filter(function(tid, index, self) { return read[index] === 0; }); @@ -563,8 +565,10 @@ var async = require('async'), unreadTids.push.apply(unreadTids, tids); callback(null); } else { - Topics.hasReadTopics(tids, uid, function(read) { - + Topics.hasReadTopics(tids, uid, function(err, read) { + if(err) { + return callback(err); + } var newtids = tids.filter(function(tid, index, self) { return parseInt(read[index], 10) === 0; }); @@ -572,11 +576,7 @@ var async = require('async'), async.filter(newtids, function(tid, next) { threadTools.privileges(tid, uid, function(err, privileges) { - if (!err && privileges.read) { - next(true); - } else { - next(false); - } + next(!err && privileges.read); }); }, function(newtids) { unreadTids.push.apply(unreadTids, newtids); @@ -692,9 +692,7 @@ var async = require('async'), } function hasReadTopic(next) { - Topics.hasReadTopic(topicData.tid, current_user, function(hasRead) { - next(null, hasRead); - }); + Topics.hasReadTopic(topicData.tid, current_user, next); } function getTeaserInfo(next) { @@ -870,9 +868,7 @@ var async = require('async'), function getReadStatus(next) { if (uid && parseInt(uid, 10) > 0) { - Topics.hasReadTopic(tid, uid, function(read) { - next(null, read); - }); + Topics.hasReadTopic(tid, uid, next); } else { next(null, null); } @@ -989,7 +985,7 @@ var async = require('async'), Topics.hasReadTopics = function(tids, uid, callback) { if(!parseInt(uid, 10)) { - return callback(tids.map(function() { + return callback(null, tids.map(function() { return false; })); } @@ -1000,25 +996,15 @@ var async = require('async'), sets.push('tid:' + tids[i] + ':read_by_uid'); } - db.isMemberOfSets(sets, uid, function(err, hasRead) { - callback(hasRead); - }); + db.isMemberOfSets(sets, uid, callback); }; Topics.hasReadTopic = function(tid, uid, callback) { if(!parseInt(uid, 10)) { - return callback(false); + return callback(null, false); } - db.isSetMember('tid:' + tid + ':read_by_uid', uid, function(err, hasRead) { - - if (err === null) { - callback(hasRead); - } else { - console.log(err); - callback(false); - } - }); + db.isSetMember('tid:' + tid + ':read_by_uid', uid, callback); }; Topics.getTeasers = function(tids, callback) {