From 23e1cc010c27b7f25c5ae56e1cac0dddfc56fabb Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sat, 8 Mar 2014 17:41:23 -0500 Subject: [PATCH 1/3] 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 2/3] 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 3/3] 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); },