mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
refactor: shorter function
This commit is contained in:
@@ -175,20 +175,16 @@ function calculateTopicPostCount(category) {
|
||||
return;
|
||||
}
|
||||
|
||||
var postCount = category.post_count;
|
||||
var topicCount = category.topic_count;
|
||||
if (!Array.isArray(category.children) || !category.children.length) {
|
||||
category.totalPostCount = postCount;
|
||||
category.totalTopicCount = topicCount;
|
||||
return;
|
||||
let postCount = category.post_count;
|
||||
let topicCount = category.topic_count;
|
||||
if (Array.isArray(category.children)) {
|
||||
category.children.forEach(function (child) {
|
||||
calculateTopicPostCount(child);
|
||||
postCount += parseInt(child.totalPostCount, 10) || 0;
|
||||
topicCount += parseInt(child.totalTopicCount, 10) || 0;
|
||||
});
|
||||
}
|
||||
|
||||
category.children.forEach(function (child) {
|
||||
calculateTopicPostCount(child);
|
||||
postCount += parseInt(child.totalPostCount, 10) || 0;
|
||||
topicCount += parseInt(child.totalTopicCount, 10) || 0;
|
||||
});
|
||||
|
||||
category.totalPostCount = postCount;
|
||||
category.totalTopicCount = topicCount;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user