return post count to with categories

v1.18.x
barisusakli 11 years ago
parent 4acc264cb8
commit cd08a16f77

@ -171,6 +171,10 @@ var db = require('./database'),
});
};
Categories.getPostCount = function(cid, callback) {
db.sortedSetCard('categories:recent_posts:cid:' + cid, callback);
};
Categories.getAllCategories = function(uid, callback) {
db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
if (err) {
@ -215,7 +219,6 @@ var db = require('./database'),
};
Categories.hasReadCategories = function(cids, uid, callback) {
var sets = [];
for (var i = 0, ii = cids.length; i < ii; i++) {
@ -237,7 +240,7 @@ var db = require('./database'),
Categories.getCategoriesData = function(cids, callback) {
var keys = cids.map(function(cid) {
return 'category:'+cid;
return 'category:' + cid;
});
db.getObjects(keys, function(err, categories) {
@ -249,15 +252,19 @@ var db = require('./database'),
return callback(null, []);
}
for (var i=0; i<categories.length; ++i) {
if (categories[i]) {
categories[i].name = validator.escape(categories[i].name);
categories[i].description = validator.escape(categories[i].description);
categories[i].backgroundImage = categories[i].image ? nconf.get('relative_path') + categories[i].image : '';
categories[i].disabled = categories[i].disabled ? parseInt(categories[i].disabled, 10) !== 0 : false;
}
}
callback(null, categories);
async.map(categories, function(category, next) {
category.name = validator.escape(category.name);
category.description = validator.escape(category.description);
category.backgroundImage = category.image ? nconf.get('relative_path') + category.image : '';
category.disabled = category.disabled ? parseInt(category.disabled, 10) !== 0 : false;
Categories.getPostCount(category.cid, function(err, postCount) {
if (err) {
return next(err);
}
category.post_count = postCount;
next(err, category);
});
}, callback);
});
};

@ -71,9 +71,11 @@ Controllers.home = function(req, res, next) {
function getRecentReplies(category, callback) {
categories.getRecentReplies(category.cid, uid, parseInt(category.numRecentReplies, 10), function (err, posts) {
if (err) {
return callback(err);
}
category.posts = posts;
category.post_count = posts.length > 2 ? 2 : posts.length; // this was a hack to make metro work back in the day, post_count should just = length
callback(null);
callback();
});
}

Loading…
Cancel
Save