more tests

This commit is contained in:
barisusakli
2016-12-02 16:10:07 +03:00
parent 091f459f5e
commit 1440139903
6 changed files with 136 additions and 43 deletions

View File

@@ -188,39 +188,37 @@ var plugins = require('./plugins');
return callback(null, []);
}
user.getSettings(uid, function (err, settings) {
if (err) {
return callback(err);
}
async.waterfall([
function (next) {
user.getSettings(uid, next);
},
function (settings, next) {
var byVotes = settings.topicPostSort === 'most_votes';
var sets = posts.map(function (post) {
return byVotes ? 'tid:' + post.tid + ':posts:votes' : 'tid:' + post.tid + ':posts';
});
var byVotes = settings.topicPostSort === 'most_votes';
var sets = posts.map(function (post) {
return byVotes ? 'tid:' + post.tid + ':posts:votes' : 'tid:' + post.tid + ':posts';
});
var uniqueSets = _.uniq(sets);
var method = 'sortedSetsRanks';
if (uniqueSets.length === 1) {
method = 'sortedSetRanks';
sets = uniqueSets[0];
}
var pids = posts.map(function (post) {
return post.pid;
});
db[method](sets, pids, function (err, indices) {
if (err) {
return callback(err);
var uniqueSets = _.uniq(sets);
var method = 'sortedSetsRanks';
if (uniqueSets.length === 1) {
method = 'sortedSetRanks';
sets = uniqueSets[0];
}
var pids = posts.map(function (post) {
return post.pid;
});
db[method](sets, pids, next);
},
function (indices, next) {
for (var i = 0; i < indices.length; ++i) {
indices[i] = utils.isNumber(indices[i]) ? parseInt(indices[i], 10) + 1 : 0;
}
callback(null, indices);
});
});
next(null, indices);
}
], callback);
};
Posts.updatePostVoteCount = function (postData, callback) {