fix for null category (#7029)

v1.18.x
SweetPPro 6 years ago committed by Barış Soner Uşaklı
parent 8a5a031db8
commit dab1a1d638

@ -85,7 +85,7 @@ module.exports = function (Categories) {
async.waterfall([ async.waterfall([
function (next) { 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'); const keys = categoriesToLoad.map(category => 'cid:' + category.cid + ':recent_tids');
db.getSortedSetsMembers(keys, next); db.getSortedSetsMembers(keys, next);
}, },
@ -153,14 +153,17 @@ module.exports = function (Categories) {
function assignTopicsToCategories(categories, topics) { function assignTopicsToCategories(categories, topics) {
categories.forEach(function (category) { categories.forEach(function (category) {
if (category) {
category.posts = topics.filter(topic => topic.cid && (topic.cid === category.cid || topic.parentCid === category.cid)) category.posts = topics.filter(topic => topic.cid && (topic.cid === category.cid || topic.parentCid === category.cid))
.sort((a, b) => b.pid - a.pid) .sort((a, b) => b.pid - a.pid)
.slice(0, parseInt(category.numRecentReplies, 10)); .slice(0, parseInt(category.numRecentReplies, 10));
}
}); });
} }
function bubbleUpChildrenPosts(categoryData) { function bubbleUpChildrenPosts(categoryData) {
categoryData.forEach(function (category) { categoryData.forEach(function (category) {
if (category) {
if (category.posts.length) { if (category.posts.length) {
return; return;
} }
@ -171,6 +174,7 @@ module.exports = function (Categories) {
if (posts.length) { if (posts.length) {
category.posts = [posts[0]]; category.posts = [posts[0]];
} }
}
}); });
} }

Loading…
Cancel
Save