Commit d7732c18 authored by 陈家荣's avatar 陈家荣

update

parent e93dc73f
......@@ -984,32 +984,43 @@ function getMobileSubThreads(doc, sort, callback) {
if (sort) {
sortBy = sort;
}
ForumThread.find(conditions, subThreadFields).populate('from', 'icon').limit(Number(20)).sort(sortBy).exec(function(err, docs) {
if (err) {
console.error(err);
callback(err, null);
} else {
var list = []; //用户去重
_.forEach(docs, function(one, i) {
var flag = true;
_.forEach(list, function(two, k) {
if(one.from._id == two.from._id){
flag = false;
async.parallel([function(cb){
ForumThread.distinct('from', conditions, cb);
},function(cb){
countAllByFid(conditions, cb);
},function(cb){
ForumThread.find(conditions, subThreadFields).populate('from', 'icon').sort(sortBy).exec(function(err, docs) {
if (err) {
console.error(err);
cb(err, null);
} else {
var list = []; //用户去重
_.forEach(docs, function(one, i) {
var flag = true;
_.forEach(list, function(two, k) {
if(one.from._id == two.from._id){
flag = false;
}
});
if(flag){
list.push(one);
}
});
if(flag){
list.push(one);
}
});
var obj = {};
obj.docTotal = docs.length;
obj.total = list.length;
obj.items = list;
var newDoc = doc.toObject();
newDoc.subThreads = obj;
callback(null, newDoc);
var obj = {};
obj.items = list;
var newDoc = {};
newDoc.subThreads = obj;
cb(null, newDoc);
}
});
}],function(err, results){
if (err) {
callback(err);
} else {
var lastResult = results[2];
lastResult.subThreads.docTotal = results[1] || 0;
lastResult.subThreads.total = results[0].length;
callback(null, lastResult);
}
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment