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

update

parent e93dc73f
...@@ -984,32 +984,43 @@ function getMobileSubThreads(doc, sort, callback) { ...@@ -984,32 +984,43 @@ function getMobileSubThreads(doc, sort, callback) {
if (sort) { if (sort) {
sortBy = sort; sortBy = sort;
} }
ForumThread.find(conditions, subThreadFields).populate('from', 'icon').limit(Number(20)).sort(sortBy).exec(function(err, docs) { async.parallel([function(cb){
if (err) { ForumThread.distinct('from', conditions, cb);
console.error(err); },function(cb){
callback(err, null); countAllByFid(conditions, cb);
} else { },function(cb){
var list = []; //用户去重 ForumThread.find(conditions, subThreadFields).populate('from', 'icon').sort(sortBy).exec(function(err, docs) {
_.forEach(docs, function(one, i) { if (err) {
var flag = true; console.error(err);
_.forEach(list, function(two, k) { cb(err, null);
if(one.from._id == two.from._id){ } else {
flag = false; 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){ var obj = {};
list.push(one); obj.items = list;
} var newDoc = {};
}); newDoc.subThreads = obj;
var obj = {}; cb(null, newDoc);
obj.docTotal = docs.length; }
obj.total = list.length; });
obj.items = list; }],function(err, results){
if (err) {
var newDoc = doc.toObject(); callback(err);
newDoc.subThreads = obj; } else {
var lastResult = results[2];
callback(null, newDoc); 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