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) {
|
Categories.getAllCategories = function(uid, callback) {
|
||||||
db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
|
db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -215,7 +219,6 @@ var db = require('./database'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
Categories.hasReadCategories = function(cids, uid, callback) {
|
Categories.hasReadCategories = function(cids, uid, callback) {
|
||||||
|
|
||||||
var sets = [];
|
var sets = [];
|
||||||
|
|
||||||
for (var i = 0, ii = cids.length; i < ii; i++) {
|
for (var i = 0, ii = cids.length; i < ii; i++) {
|
||||||
@@ -237,7 +240,7 @@ var db = require('./database'),
|
|||||||
|
|
||||||
Categories.getCategoriesData = function(cids, callback) {
|
Categories.getCategoriesData = function(cids, callback) {
|
||||||
var keys = cids.map(function(cid) {
|
var keys = cids.map(function(cid) {
|
||||||
return 'category:'+cid;
|
return 'category:' + cid;
|
||||||
});
|
});
|
||||||
|
|
||||||
db.getObjects(keys, function(err, categories) {
|
db.getObjects(keys, function(err, categories) {
|
||||||
@@ -249,15 +252,19 @@ var db = require('./database'),
|
|||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i=0; i<categories.length; ++i) {
|
async.map(categories, function(category, next) {
|
||||||
if (categories[i]) {
|
category.name = validator.escape(category.name);
|
||||||
categories[i].name = validator.escape(categories[i].name);
|
category.description = validator.escape(category.description);
|
||||||
categories[i].description = validator.escape(categories[i].description);
|
category.backgroundImage = category.image ? nconf.get('relative_path') + category.image : '';
|
||||||
categories[i].backgroundImage = categories[i].image ? nconf.get('relative_path') + categories[i].image : '';
|
category.disabled = category.disabled ? parseInt(category.disabled, 10) !== 0 : false;
|
||||||
categories[i].disabled = categories[i].disabled ? parseInt(categories[i].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) {
|
function getRecentReplies(category, callback) {
|
||||||
categories.getRecentReplies(category.cid, uid, parseInt(category.numRecentReplies, 10), function (err, posts) {
|
categories.getRecentReplies(category.cid, uid, parseInt(category.numRecentReplies, 10), function (err, posts) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
category.posts = posts;
|
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();
|
||||||
callback(null);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user