Commit 8db3f65a authored by strong's avatar strong

Merge branch 'bugfix_0520_subthread_limit' into SANDBOX

parents f4505aff 0674469f
...@@ -785,10 +785,15 @@ function getSubThreads(doc, sort, callback) { ...@@ -785,10 +785,15 @@ function getSubThreads(doc, sort, callback) {
if (sort) { if (sort) {
sortBy = sort; sortBy = sort;
} }
ForumThread.find(conditions, subThreadFields).populate('from', 'icon').sort(sortBy).exec(function(err, docs) { async.parallel([function(cb){
ForumThread.distinct('from', conditions, cb);
},function(cb){
countAllByFid(conditions, cb);
},function(cb){
ForumThread.find(conditions, subThreadFields).populate('from', 'icon').limit(Number(20)).sort(sortBy).exec(function(err, docs) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); cb(err, null);
} else { } else {
var list = []; //用户去重 var list = []; //用户去重
_.forEach(docs, function(one, i) { _.forEach(docs, function(one, i) {
...@@ -803,14 +808,20 @@ function getSubThreads(doc, sort, callback) { ...@@ -803,14 +808,20 @@ function getSubThreads(doc, sort, callback) {
} }
}); });
var obj = {}; var obj = {};
obj.docTotal = docs.length;
obj.total = list.length;
obj.items = list; obj.items = list;
var newDoc = doc.toObject(); var newDoc = doc.toObject();
newDoc.subThreads = obj; newDoc.subThreads = obj;
cb(null, newDoc);
callback(null, newDoc); }
});
}],function(err, results){
if (err) {
callback(err);
} else {
var lastResult = results[2];
lastResult.subThreads.docTotal = result[1] || 0;
lastResult.subThreads.total = result[0];
callback(null, lastResult);
} }
}); });
} }
...@@ -827,7 +838,7 @@ function getMobileSubThreads(doc, sort, callback) { ...@@ -827,7 +838,7 @@ function getMobileSubThreads(doc, sort, callback) {
if (sort) { if (sort) {
sortBy = sort; sortBy = sort;
} }
ForumThread.find(conditions, subThreadFields).populate('from', 'icon').sort(sortBy).exec(function(err, docs) { ForumThread.find(conditions, subThreadFields).populate('from', 'icon').limit(Number(20)).sort(sortBy).exec(function(err, docs) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
......
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