small optimizations

user.isOnline works with an array of uids
do not make 2 trips to db to get main post and first 10 posts
This commit is contained in:
barisusakli
2014-08-12 11:19:17 -04:00
parent c818a37f0f
commit c07d9121df
4 changed files with 73 additions and 55 deletions

View File

@@ -93,7 +93,7 @@ var async = require('async'),
};
Posts.getPostsByTid = function(tid, set, start, end, reverse, callback) {
db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, end, function(err, pids) {
Posts.getPidsFromSet(set, start, end, reverse, function(err, pids) {
if(err) {
return callback(err);
}
@@ -102,31 +102,15 @@ var async = require('async'),
return callback(null, []);
}
Posts.getPostsByPids(pids, function(err, posts) {
if(err) {
return callback(err);
}
if(!Array.isArray(posts) || !posts.length) {
return callback(null, []);
}
plugins.fireHook('filter:post.getPosts', {tid: tid, posts: posts}, function(err, data) {
if(err) {
return callback(err);
}
if(!data || !Array.isArray(data.posts)) {
return callback(null, []);
}
callback(null, data.posts);
});
});
Posts.getPostsByPids(pids, tid, callback);
});
};
Posts.getPostsByPids = function(pids, callback) {
Posts.getPidsFromSet = function(set, start, end, reverse, callback) {
db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, end, callback);
};
Posts.getPostsByPids = function(pids, tid, callback) {
var keys = [];
for(var x=0, numPids=pids.length; x<numPids; ++x) {
@@ -155,7 +139,23 @@ var async = require('async'),
next(null, postData);
});
}, callback);
}, function(err, posts) {
if (err) {
return callback(err);
}
plugins.fireHook('filter:post.getPosts', {tid: tid, posts: posts}, function(err, data) {
if (err) {
return callback(err);
}
if (!data || !Array.isArray(data.posts)) {
return callback(null, []);
}
callback(null, data.posts);
});
});
});
};