Permalink
Browse files

优化性能瓶颈

  • Loading branch information...
1 parent 9c940c4 commit 7715db59e47e019216daafa265276c42d5883096 @alsotang alsotang committed Feb 25, 2014
Showing with 18 additions and 12 deletions.
  1. +12 −10 controllers/user.js
  2. +6 −2 proxy/reply.js
View
@@ -53,17 +53,19 @@ exports.index = function (req, res, next) {
var opt = {limit: 5, sort: [['create_at', 'desc']]};
Topic.getTopicsByQuery(query, opt, proxy.done('recent_topics'));
- Reply.getRepliesByAuthorId(user._id, proxy.done(function (replies) {
- var topic_ids = [];
- for (var i = 0; i < replies.length; i++) {
- if (topic_ids.indexOf(replies[i].topic_id.toString()) < 0) {
- topic_ids.push(replies[i].topic_id.toString());
+ Reply.getRepliesByAuthorId(user._id, {limit: 20, sort: [['create_at', 'desc']]},
+ proxy.done(function (replies) {
+ console.log(replies);
+ var topic_ids = [];
+ for (var i = 0; i < replies.length; i++) {
+ if (topic_ids.indexOf(replies[i].topic_id.toString()) < 0) {
+ topic_ids.push(replies[i].topic_id.toString());
+ }
}
- }
- var query = {_id: {'$in': topic_ids}};
- var opt = {limit: 5, sort: [['create_at', 'desc']]};
- Topic.getTopicsByQuery(query, opt, proxy.done('recent_replies'));
- }));
+ var query = {_id: {'$in': topic_ids}};
+ var opt = {limit: 5, sort: [['create_at', 'desc']]};
+ Topic.getTopicsByQuery(query, opt, proxy.done('recent_replies'));
+ }));
if (!req.session.user) {
proxy.emit('relation', null);
View
@@ -145,6 +145,10 @@ exports.newAndSave = function (content, topicId, authorId, replyId, callback) {
});
};
-exports.getRepliesByAuthorId = function (authorId, callback) {
- Reply.find({author_id: authorId}, callback);
+exports.getRepliesByAuthorId = function (authorId, opt, callback) {
+ if (!callback) {
+ callback = opt;
+ opt = null;
+ }
+ Reply.find({author_id: authorId}, {}, opt, callback);
};

0 comments on commit 7715db5

Please sign in to comment.