mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 10:06:13 +01:00
return post count to with categories
This commit is contained in:
@@ -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++) {
|
||||
@@ -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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
callback(null, categories);
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user