mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 06:25:50 +01:00
added async.eachSeries to getCategories
This commit is contained in:
@@ -369,32 +369,41 @@ var RDB = require('./redis.js'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
Categories.getCategories = function(cids, callback, current_user) {
|
Categories.getCategories = function(cids, callback, current_user) {
|
||||||
if (!cids || cids.length === 0) {
|
if (!cids || !Array.isArray(cids) || cids.length === 0) {
|
||||||
callback({'categories' : []});
|
callback({'categories' : []});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var categories = [];
|
var categories = [];
|
||||||
|
|
||||||
for(var i=0; i<cids.length; ++i) {
|
function getCategory(cid, callback) {
|
||||||
Categories.getCategoryData(cids[i], function(err, categoryData) {
|
Categories.getCategoryData(cid, function(err, categoryData) {
|
||||||
|
|
||||||
if(err)
|
if(err) {
|
||||||
|
callback(err);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Categories.hasReadCategory(categoryData.cid, current_user, function(hasRead) {
|
Categories.hasReadCategory(cid, current_user, function(hasRead) {
|
||||||
categoryData['badgeclass'] = (parseInt(categoryData.topic_count,10) === 0 || (hasRead && current_user != 0)) ? '' : 'badge-important';
|
categoryData['badgeclass'] = (parseInt(categoryData.topic_count,10) === 0 || (hasRead && current_user != 0)) ? '' : 'badge-important';
|
||||||
|
|
||||||
categories.push(categoryData);
|
categories.push(categoryData);
|
||||||
|
callback(null);
|
||||||
if(categories.length === cids.length)
|
|
||||||
callback({'categories': categories});
|
|
||||||
|
|
||||||
}) ;
|
}) ;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async.eachSeries(cids, getCategory, function(err) {
|
||||||
|
if(err) {
|
||||||
|
console.log(err);
|
||||||
|
callback(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback({'categories': categories});
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}(exports));
|
}(exports));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user