diff --git a/src/categories.js b/src/categories.js index 6112c5dc58..134a671744 100644 --- a/src/categories.js +++ b/src/categories.js @@ -159,7 +159,11 @@ var async = require('async'), category.disabled = parseInt(category.disabled, 10) === 1; category.icon = category.icon || 'hidden'; if (category.hasOwnProperty('post_count')) { - category.post_count = category.post_count || 0; + category.post_count = category.totalPostCount = category.post_count || 0; + } + + if (category.hasOwnProperty('topic_count')) { + category.topic_count = category.totalTopicCount = category.topic_count || 0; } if (category.description) { @@ -250,18 +254,23 @@ var async = require('async'), }; function calculateTopicPostCount(category) { - if (!Array.isArray(category.children) || !category.children.length) { + if (!category) { return; } var postCount = parseInt(category.post_count, 10) || 0; var topicCount = parseInt(category.topic_count, 10) || 0; + if (!Array.isArray(category.children) || !category.children.length) { + category.totalPostCount = postCount; + category.totalTopicCount = topicCount; + return; + } category.children.forEach(function(child) { postCount += parseInt(child.post_count, 10) || 0; topicCount += parseInt(child.topic_count, 10) || 0; }); - category.post_count = postCount; - category.topic_count = topicCount; + category.totalPostCount = postCount; + category.totalTopicCount = topicCount; } Categories.getParents = function(cids, callback) {