removed most of the db.sortedSetCards

This commit is contained in:
barisusakli
2014-10-14 23:12:47 -04:00
parent 09bd42b9f6
commit 761f56aeb1
8 changed files with 25 additions and 20 deletions

View File

@@ -77,11 +77,11 @@ var async = require('async'),
};
Topics.getPageCount = function(tid, uid, callback) {
db.sortedSetCard('tid:' + tid + ':posts', function(err, postCount) {
if(err) {
Topics.getTopicField(tid, 'postcount', function(err, postCount) {
if (err) {
return callback(err);
}
if(!parseInt(postCount, 10)) {
if (!parseInt(postCount, 10)) {
return callback(null, 1);
}
user.getSettings(uid, function(err, settings) {
@@ -346,15 +346,22 @@ var async = require('async'),
};
Topics.getTeasers = function(tids, uid, callback) {
if(!Array.isArray(tids) || !tids.length) {
if (!Array.isArray(tids) || !tids.length) {
return callback(null, []);
}
async.parallel({
counts: function(next) {
async.map(tids, function(tid, next) {
db.sortedSetCard('tid:' + tid + ':posts', next);
}, next);
Topics.getTopicsFields(tids, ['postcount'], function(err, topics) {
if (err) {
return next(err);
}
topics = topics.map(function(topic) {
return topic && topic.postcount;
});
next(null, topics);
});
},
pids: function(next) {
async.map(tids, function(tid, next) {