From 33e34ca8644cc95696f738d307e97730d71215ff Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 11 Mar 2014 23:31:23 -0400 Subject: [PATCH 1/3] change getRecentPosts to take count --- src/socket.io/posts.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index 3f6b9320d0..fedb968522 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -296,8 +296,12 @@ SocketPosts.loadMoreUserPosts = function(socket, data, callback) { }; -SocketPosts.getRecentPosts = function(socket, term, callback) { - posts.getRecentPosts(socket.uid, 0, 19, term, callback); +SocketPosts.getRecentPosts = function(socket, data, callback) { + if(!data || !data.count) { + return callback(new Error('invalid data')); + } + + posts.getRecentPosts(socket.uid, 0, data.count - 1, data.term, callback); }; From e9ab9dcce26ac3a2d94a89885017bc235ea611ad Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 12 Mar 2014 00:13:42 -0400 Subject: [PATCH 2/3] search cleanup --- public/src/utils.js | 8 +++-- src/controllers/index.js | 71 +++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/public/src/utils.js b/public/src/utils.js index c37479547d..44d348b096 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -8,9 +8,13 @@ XRegExp = require('xregexp').XRegExp; process.profile = function(operation, start) { + console.log('%s took %d milliseconds', process.elapsedTimeSince(start)); + }; + + process.elapsedTimeSince = function(start) { var diff = process.hrtime(start); - console.log('%s took %d milliseconds', operation, diff[0] * 1e3 + diff[1] / 1e6); - } + return diff[0] * 1e3 + diff[1] / 1e6; + }; } else { XRegExp = window.XRegExp; diff --git a/src/controllers/index.js b/src/controllers/index.js index 4e323ce190..0cf3fde55b 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -87,11 +87,10 @@ Controllers.home = function(req, res, next) { }; Controllers.search = function(req, res, next) { + var start = process.hrtime(); + if (!req.params.term) { return res.render('search', { - show_no_topics: 'hide', - show_no_posts: 'hide', - show_results: 'hide', search_query: '', posts: [], topics: [] @@ -102,51 +101,49 @@ Controllers.search = function(req, res, next) { return res.redirect('/404'); } - function searchPosts(callback) { + function search(index, callback) { plugins.fireHook('filter:search.query', { - index: 'post', + index: index, query: req.params.term - }, function(err, pids) { - if (err) { - return callback(err); - } - - posts.getPostSummaryByPids(pids, false, callback); - }); - } - - function searchTopics(callback) { - plugins.fireHook('filter:search.query', { - index: 'topic', - query: req.params.term - }, function(err, tids) { - if (err) { - return callback(err); - } - - topics.getTopicsByTids(tids, 0, callback); - }); + }, callback); } - async.parallel([searchPosts, searchTopics], function (err, results) { + async.parallel({ + pids: function(next) { + search('post', next); + }, + tids: function(next) { + search('topic', next); + } + }, function (err, results) { if (err) { return next(err); } if(!results) { - results = []; - results[0] = results[1] = []; + results = {pids:[], tids: []}; } - return res.render('search', { - show_no_topics: results[1].length ? 'hide' : '', - show_no_posts: results[0].length ? 'hide' : '', - show_results: '', - search_query: req.params.term, - posts: results[0], - topics: results[1], - post_matches : results[0].length, - topic_matches : results[1].length + async.parallel({ + posts: function(next) { + posts.getPostSummaryByPids(results.pids, false, next); + }, + topics: function(next) { + topics.getTopicsByTids(results.tids, 0, next); + } + }, function(err, results) { + if (err) { + return next(err); + } + + return res.render('search', { + time: process.elapsedTimeSince(start), + search_query: req.params.term, + posts: results.posts, + topics: results.topics, + post_matches : results.posts.length, + topic_matches : results.topics.length + }); }); }); }; From a0222b69bb6043740aab226386d99cd9131d71d2 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 12 Mar 2014 00:45:15 -0400 Subject: [PATCH 3/3] closes #1200 --- src/topics.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/topics.js b/src/topics.js index 680d0d2bac..1ac9e6b7d1 100644 --- a/src/topics.js +++ b/src/topics.js @@ -737,8 +737,7 @@ var async = require('async'), userCache[topicData.uid] = topicInfo.user; if (!isTopicVisible(topicData, topicInfo)) { - topicData = null; - return next(); + return next(null, null); } topicData.pinned = parseInt(topicData.pinned, 10) === 1; @@ -751,7 +750,7 @@ var async = require('async'), topicData.teaser = topicInfo.teaser; topicData.user = topicInfo.user; - next(); + next(null, topicData); }); } @@ -760,7 +759,7 @@ var async = require('async'), return callback(err); } - async.eachSeries(topics, loadTopicInfo, function(err) { + async.mapSeries(topics, loadTopicInfo, function(err, topics) { if(err) { return callback(err); }