Commit 8604faf4 authored by strong's avatar strong

Merge branch 'remould_0727_topic_cache' into SANDBOX

parents b3f59255 bf6b7648
......@@ -348,6 +348,8 @@ exports.getThreadById = function(tid, callback) {
cb(null, null);
return;
}
getAllThreadByFidHelp(conditions, 1, 10, null, function(err, threads) {
if (err) {
console.error(err);
......@@ -401,26 +403,56 @@ exports.getThreadById = function(tid, callback) {
},
function(cb) {
//获取发帖人数
ForumThread.aggregate({
$match: {
pid: mongoose.Types.ObjectId(tid)
}
}, {
$group: {
_id: {
from: '$from'
},
count: {
$sum: 1
}
}
}, function(err, data) {
if (err) {
cb(err, null);
var key = 'pisns-forum-thread:' + tid + ':amount';
redis.get(key,function(err,value){
if (value) {
cb(null, Number(value));
} else {
cb(null, data.length);
ForumThread.aggregate({
$match: {
pid: mongoose.Types.ObjectId(tid)
}
}, {
$group: {
_id: {
from: '$from'
},
count: {
$sum: 1
}
}
}, function(err, data) {
if (err) {
cb(err, null);
} else {
redis.set(key, data.length);
redis.expire(key, 10);
cb(null, data.length);
}
});
}
});
}
// ForumThread.aggregate({
// $match: {
// pid: mongoose.Types.ObjectId(tid)
// }
// }, {
// $group: {
// _id: {
// from: '$from'
// },
// count: {
// $sum: 1
// }
// }
// }, function(err, data) {
// if (err) {
// cb(err, null);
// } else {
// cb(null, data.length);
// }
// });
}
], function(err, results) {
if (err) {
......
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