late night optimizations

-isMemberOfSets returns true/false instead of 1/0
-when loading the posts of a topic only get the userdata for each user
once, before this commit if a topic had 10 posts from 2 different users
we were getting the user data for each user 5 times (drunk)
-getVoteStatusByPostIDs and getFavouritesByPostIDs no longer make
pids.length calls to the db, they use isMemberOfSets now
-getUserInfoForPost renamed to getUserInfoForPosts and doesnt make
uids.length calls to db, uses getMultipleUserFields instead
This commit is contained in:
barisusakli
2014-06-28 01:03:26 -04:00
parent d3fc71529a
commit c3a9767bf6
9 changed files with 137 additions and 86 deletions

View File

@@ -270,6 +270,9 @@ var async = require('async'),
}
async.parallel({
mainPost: function(next) {
Topics.getMainPost(tid, uid, next);
},
posts: function(next) {
Topics.getTopicPosts(tid, set, start, end, uid, reverse, next);
},
@@ -284,26 +287,6 @@ var async = require('async'),
},
tags: function(next) {
Topics.getTopicTagsObjects(tid, next);
},
mainPost: function(next) {
Topics.getTopicField(tid, 'mainPid', function(err, mainPid) {
if (err) {
return next(err);
}
if (!parseInt(mainPid, 10)) {
return next(null, []);
}
posts.getPostsByPids([mainPid], function(err, postData) {
if (err) {
return next(err);
}
if (!Array.isArray(postData) || !postData[0]) {
return next(null, []);
}
postData[0].index = 0;
Topics.addPostData(postData, uid, next);
});
});
}
}, function(err, results) {
if (err) {
@@ -325,6 +308,27 @@ var async = require('async'),
});
};
Topics.getMainPost = function(tid, uid, callback) {
Topics.getTopicField(tid, 'mainPid', function(err, mainPid) {
if (err) {
return callback(err);
}
if (!parseInt(mainPid, 10)) {
return callback(null, []);
}
posts.getPostsByPids([mainPid], function(err, postData) {
if (err) {
return callback(err);
}
if (!Array.isArray(postData) || !postData[0]) {
return callback(null, []);
}
postData[0].index = 0;
Topics.addPostData(postData, uid, callback);
});
});
};
Topics.getTeasers = function(tids, callback) {
if(!Array.isArray(tids)) {