mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 10:46:14 +01:00
fix for null category (#7029)
This commit is contained in:
committed by
Barış Soner Uşaklı
parent
8a5a031db8
commit
dab1a1d638
@@ -85,7 +85,7 @@ module.exports = function (Categories) {
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
const categoriesToLoad = categoryData.filter(category => parseInt(category.numRecentReplies, 10) > 0);
|
||||
const categoriesToLoad = categoryData.filter(category => category && category.numRecentReplies && parseInt(category.numRecentReplies, 10) > 0);
|
||||
const keys = categoriesToLoad.map(category => 'cid:' + category.cid + ':recent_tids');
|
||||
db.getSortedSetsMembers(keys, next);
|
||||
},
|
||||
@@ -153,14 +153,17 @@ module.exports = function (Categories) {
|
||||
|
||||
function assignTopicsToCategories(categories, topics) {
|
||||
categories.forEach(function (category) {
|
||||
if (category) {
|
||||
category.posts = topics.filter(topic => topic.cid && (topic.cid === category.cid || topic.parentCid === category.cid))
|
||||
.sort((a, b) => b.pid - a.pid)
|
||||
.slice(0, parseInt(category.numRecentReplies, 10));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function bubbleUpChildrenPosts(categoryData) {
|
||||
categoryData.forEach(function (category) {
|
||||
if (category) {
|
||||
if (category.posts.length) {
|
||||
return;
|
||||
}
|
||||
@@ -171,6 +174,7 @@ module.exports = function (Categories) {
|
||||
if (posts.length) {
|
||||
category.posts = [posts[0]];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user